Say I don’t know what an element’s name will be, but I do know what it’s children will be. For example, the names “foo” and “bar” are not prescribed but “A”, “B” & “C” are.
<example>
<foo>
<A>A</A>
<B>B</B>
<C>C</C>
</foo>
<bar>
<A>A</A>
<B>B</B>
<C>C</C>
</bar>
</example>
I cannot leave the name attribute out because that’s a violation. I would expect to be able to do this instead:
<xs:element name="example">
<xs:complexType>
<xs:sequence maxOccurs="unbounded">
<xs:any>
<xs:complexType>
<xs:sequence>
<xs:element name="A" type="xs:string"/>
<xs:element name="B" type="xs:string"/>
<xs:element name="C" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:any>
</xs:sequence>
</xs:complexType>
</xs:element>
This does not work either, <xs:any> can only contain annotations and refuses a type.
Is there something I can do with namespaces that will work with unknown element names? Should I give up, not attempt to validate the children and just document what the contents must be?
You cannot quite achieve what you want to do there in XML Schema. There is a close solution, but not quite what you want:
Now you could provide separate schemas for the elements that can occur in there, e.g. one for
foo, under a separate namespace and in a separate schema file:That’s about all you can do (it’s your “multiple namespaces” solution). You can’t avoid listing the elements entirely. If that’s not good enough, then
<xsd:any>withprocessContentsset toskipis your only solution, followed by external validation (code, Schematron, etc)