2

Is it possible to use inheritance in xsd with variable element order?

Basically, something like this does not work, since "all" is not allowed inside "extension":

<xs:complexType name="root">
    <xs:complexContent>
          <xs:all>
              <xs:element name="A" type="xs:string"/>
              <xs:element name="B" type="xs:string"/>
          </xs:all>
    </xs:complexContent>
</xs:complexType>

<xs:complexType name="extended">
    <xs:complexContent>
        <xs:extension base="root"> 
            <xs:all>
              <xs:element name="C" type="xs:string"/>
              <xs:element name="D" type="xs:string"/>
            </xs:all>
        </xs:extension>
    </xs:complexContent>
</xs:complexType>

The simplest solution would be just to use "sequence" instead of "all", but in my case this is not an option, since the element order is not guaranteed, so something like this:

<obj>
  <B/>
  <C/>
  <D/>
  <A/>
</obj>

will be invalid because of the wrong element order, but is should not be since all the elements are present.

1 Answer 1

1

Your example is legal in XSD 1.1, which became a Recommendation last week. XSD 1.1 is implemented in Xerces and in Saxon.

1
  • I've just tested this in Java with a Xerces beta parser which supports 1.1 XML Schema, and got the same error as before - where else / how can I test if the schema is indeed legal according to XSD 1.1 specs?
    – Shajirr
    Apr 23, 2012 at 23:26

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.