Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In an XSD schema, how do I say that an element might have any number of subelements that must inherit from a certain type?

Tags:

xsd

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.

like image 451
Hanno Fietz Avatar asked Nov 14 '22 15:11

Hanno Fietz


1 Answers

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.

like image 124
bendin Avatar answered Jun 09 '23 06:06

bendin