Is it possible using one or more XSDs to validate the following xml structure
<container>
<unkownA />
<unkownB />
<unkownC />
...
<data />
</container>
by those rules
- there is an unlimited number of unkown elements
- there is at least one of those unkown elements
- the last element is data
- data occurs only once
- data is validated according to provided rules
All the elements in the xml have the same namespace (“”), which we can’t change.
We are most likely not able to change the order of the elements as well, though I know this is probably the easiest solution.
Changing the xml in general is not an viable option, since it is generated by a external system we don’t control.
I tried something like this
<xs:sequence>
<xs:any minOccurs="1" maxOccurs="unbounded" processContents="lax" />
<xs:element ref="data" minOccurs="1" />
</xs:sequence>
which of course, being ambiguous, violates the “Unique Particle Attribution”.
I also read about the use of a second namespace here Creating a 'flexible' XML schema
but since we can’t change the xml this does not seem to be a solution or I plainly don’t understand it properly.
By the we are using Java to process the xml/xsd, the xsd resides in the classpath, so xs:import from within an xsd might be a problem.
If the answer is “This can’t be done with xsd within these constraints” I’m fine with it.
So any ideas?
What finally worked, even if it does not make me happy:
This seems to disable the validation of the schema itself.
The validation of the xml works as expected and described above.
And yes, I know: Disabling security/sanity features that are actived by default might not be a good idea. But till know there wasn’t any time to find a better way.