Let's say I have an XML document (represented as text, a W3C DOM, etc.), as well as an XML schema. An XML document has all the correct elements defined by the schema, but in the wrong order.
How to use a scheme to "reorder" document elements in accordance with the order defined by the scheme?
I know this should be possible, possibly using XSOM , because the JAXB XJC code generator annotates its generated classes with the correct ordering of the elements.
However, I am not familiar with the XSOM API, and it is pretty tight, so I hope you have a lot of experience and can point me in the right direction. Something like "which children are allowed inside this parent and in what order?"
Let me give you an example.
I have an XML document like this:
<A> <Y/> <X/> </A>
I have an XML schema that says that the contents of <A> should be <X> , followed by <Y> . Now itβs clear that if I try to check the document for a diagram, it fails because <X> and <Y> are in the wrong order. But I know that my document is "wrong" in advance, so I still do not use the scheme for verification. However, I know that my document has all the correct elements defined by the schema in the wrong order.
What I want to do is programmatically examine the Schema (possibly using the XSOM object model for the XML Schema) and ask it what the contents of the <A> should be. The API will provide information that "you will need <X> and then <Y> ".
So, I take my XML document (using the DOM API) and rebuild and, accordingly, so now the document will be checked for compliance with the scheme.
It is important to understand what XSOM is - it is a java API that represents the information contained in the XML schema, and not the information contained in my copy of the document.
What I do not want to do is generate code from the circuit, since the circuit is unknown at build time. In addition, XSLT is useless because the correct order of elements is determined solely by the data dictionary contained in the schema.
Hope that is now fairly explicit.