MAK
MAK

Reputation: 615

XML Schema validation containing ASSERT Tag

I am trying to validate a XML instance with a XML Schema which contains an assert tag in it. The validator throws an exception containing the message:

The content of '#AnonType_message' is invalid. Element 'assert' is invalid, misplaced, or occurs too often.

This is my code:

//xmlData is a xml string
Source xmlFile = new StreamSource(new StringReader( xmlData ));

SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);

Schema schema = schemaFactory.newSchema(schemaFile);
Validator validator = schema.newValidator();

validator.validate(xmlFile);

This is the parser's error message:

org.xml.sax.SAXParseException

Upvotes: 1

Views: 2148

Answers (1)

helderdarocha
helderdarocha

Reputation: 23637

The <assert> tag is valid in XSD 1.1 schemas.

To validate your schema you will need a XSD 1.1 compatible parser. See this question and the answer for an example on how to configure it in your application.

You might also want to check if your XSD document has these two attributes in the <xs:schema> start tag:

<xs:schema ...
       xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" vc:minVersion="1.1" ...>

Upvotes: 2

Related Questions