2
votes

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"

2

2 Answers

2
votes

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>
1
votes

XSD does not identify any class of elements as "array elements", so it's not entirely clear what you mean by your question. There is no requirement in XSD that all children of an element have the same name, or the same type.

XSD does require, by means of the "Element Declarations Consistent" constraint, that any two siblings with the same name have the same type (or compatible types, with 'compatibility' defined by some rather dense and complicated prose).

Since heterogeneous arrays cause difficulties in some programming languages, I can imagine some programmers wanting to design their XML to avoid constructs which would map into heterogeneous arrays. But the design of XHTML is in no sense non-standard.