mnemy
mnemy

Reputation: 679

Extended type - inherited element ordering

I'm using extended types in my XSD for common element sequences I need in multiple types. However, I want to control the ordering in which the inherited elements are placed into the sequence. This is what I have:

<xs:complexType name="subType">
  <xs:complexContent>
    <xs:extension base="baseType">
      <xs:sequence>
        <xs:element name="name" type="xs:string"/>
      </xs:sequence>
    </xs:extension>
  </xs:complexContent>
</xs:complexType>

<xs:complexType name="baseType">
  <xs:sequence>
    <xs:element name="element1" type="xs:string"/>
    <xs:element name="element2" type="xs:string"/>
  </xs:sequence>
</xs:complexType>

This is the resulting ordering:

<subType>
  <element1>element1</element1>
  <element2>element2</element2>
  <name>name</name>
</subType>

I would like the sequence defined in subType to appear first in the sequence, to achieve:

<subType>
  <name>name</name>
  <element1>element1</element1>
  <element2>element2</element2>
</subType>

Is this possible? I understand that overall, it's the same data being represented, but I'd like to control the order so I can make it as intuitive as possible.

Upvotes: 2

Views: 109

Answers (1)

Petru Gardea
Petru Gardea

Reputation: 21638

Within the same compiled set, it is not possible to achieve such a thing. If reuse is at the top of your list (as opposed to object orientation), then you could achieve reuse of content through <xs:group/>s i.e. group1 would have <element1/> and <element2/>, group2 would have <name/>; in different types, you could change the relative position of group1 and group2 to suit your needs.

Across different sets, you could achieve variation, by using redefines (two redefines). However, even in this case, the base type content would show before the subtype. I would not recommend the trouble, if only because most of the tools that use XSDs to code bindings would not work with <xs:redefine/>s.

Upvotes: 1

Related Questions