Say I have these types defined in my XSD:
<complexType name="NamedEntity">
<attribute name="ix" type="positiveInteger"></attribute>
<attribute name="sName" type="string"></attribute>
<attribute name="txtDesc" type="string"></attribute>
</complexType>
<complexType name="Node">
<complexContent>
<extension base="tns:NamedEntity">
</extension>
</complexContent>
</complexType>
<complexType name="Source">
<complexContent>
<extension base="tns:NamedEntity">
<attribute name="dt" type="dateTime"></attribute>
</extension>
</complexContent>
</complexType>
Now I want to express that a Node
element may have zero or more child elements that may be of the type Node
or Source
.
It would be OK if I had to somehow enumerate the allowed types for the children, but since I have more types that inherit from NamedEntity
, it would be neat if I could specify just the base type.
Edit: I'd rather not use xsi:type
in the document but have a unambigous relationship between element name and type. Quite a lot XML processing seems to depend on that, and I also find it a lot more readable.
Please don't use xsi:type
if you can avoid it. It's evil. Ok, maybe I exaggerate, but it does make it impossible to parse the document without intimate knowledge of the schema, which is bad enough in practice.
What will help you is: substitutionGroup
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With