Java – Ignore element order while validating XML against XSD

javaxmlxsd

We have an XML which needs to be validated against an XSD. The XML is being generated by XSTREAM. and We are using jaxp api's to validate the XML against the respective XSD. Unfortunately, currently our test case fail as the generated XML has elements/Tags in different order/sequence than the XSD.

Is it possible to ignore the order of elements in generated XML while validating it against XSD?

Thanks for the help in advance.

Best Answer

What you are asking for is a way to say "validate some of the XSD and ignore other parts". I don't think that can be done.

One possible solution would be to modify the schema so that instead of using a <sequence> for those elements (which requires that the elements be in a particular order) you can use <all>, which allows the elements to be in any order.

The point of a schema is to impose certain structure and requirements on an XML document. You can't just say "eh, I don't like that particular part of the schema, ignore it" as then the document doesn't conform to the schema anymore.

Related Topic