Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore element order while validating XML against XSD

Tags:

java

xml

xsd

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.

like image 638
Priyank Avatar asked Aug 19 '09 12:08

Priyank


People also ask

Does order of elements matter in XML?

XML Specification Generally speaking, the order in which child elements appear inside their parent element container in XML shouldn't matter.

Can we validate XML documents against so schema?

You can validate your XML documents against XML schemas only; validation against DTDs is not supported. However, although you cannot validate against DTDs, you can insert documents that contain a DOCTYPE or that refer to DTDs.

What is minOccurs in XSD?

The minOccurs attribute specifies the minimum number of times that the element can occur. It can have a value of 0 or any positive integer. The maxOccurs attribute specifies the maximum number of times that the element can occur.


1 Answers

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.

like image 189
Adam Batkin Avatar answered Nov 08 '22 13:11

Adam Batkin