Search code examples
xmlxsduml

XML Schema - Element with maxOccurs="unbounded" containing multiple acceptable types


is it possible to make XSD schema for an element with maxOccurs="unbounded" which accepts different value types as its items? for example:

<myArray>
    <A>first</A>
    <A>second</A>
    <A>third</A>
    <B>fourth</B>
    <B>fifth</B>
</myArray>

if not, is it a non-standard type of designing XML structures?

similarly in XHTML:

<body>
    <p></p>
    <br />
    <img />
</body>

is this mean that xhtml is not standard?

Updated: maxOccurs="unbounded" previously was called "Array Element"


Solution

  • well, i found the way by using xsd refs. Conclusion: It is possible and XHTML is standard.

    schema for "myArray":

    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
        <xs:element name="A" type="xs:string" />
        <xs:element name="B" type="xs:string" />
        <xs:element name="myArray">
            <xs:complexType>
                <xs:sequence>
                    <xs:element ref="A" minOccurs="0" maxOccurs="unbounded" />
                    <xs:element ref="B" minOccurs="0" maxOccurs="unbounded" />
                </xs:sequence>
            </xs:complexType>
        </xs:element>
    </xs:schema>