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?
Asked
Active
Viewed 104 times
1 Answers
1
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:
- Fix the XSD to allow the order you want to use
- Fix the XML
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.

Abel
- 56,041
- 24
- 146
- 247
-
This isn't quite what I'm looking for, but at this point I'm pretty sure that an easy solution for this does not exist and we're just going to have to end up modifying the xsd to ignore the order. – Stephen Brown Sep 23 '15 at 17:29
-
@stephen that's probably the best approach. The data is currently invalid. You can fix the data, or fix the schema. If you're going to allow differing orders, fixing the schema seems appropriate – Abel Sep 23 '15 at 18:23