I'm dynamically generating a document that needs to be validated against a schema at runtime. The problem I'm running into is that the structure of the document is correct, but the sequence of elements at each level is not. Is there a way to tell the transformer to write out the elements in the order specified by an xsd file? or am I going to have to parse the xsd and sort it manually?
Is there a way to tell the transformer to write out the elements in the order specified by an xsd file?
If with the transformer you mean the validator, then no. If the order is incorrect you can do two things:
If you are handy with XSLT, it is trivial to change the order of the XML. You may even use the XSD as secondary input and automatically order based on the appearances of xs:sequence
, or you create a list of places where a certain order is required and dynamically sort using xsl:sort
or another way or ordering.