XSD type inheritance question: Can "extended" elements be before "base" elements?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi,
I have an xsd schema defined that has a base (abstract) type and two (concrete) types with that base.
Each concrete type adds some elements to the base type.
Is there a way that the concrete types can have their-defined elements listed before the base-defined elements.
Heres an example of what I have, and what I want (essentially, I want the "unique identifier"--which is defined in the concrete type--to be the first element(s) listed in the xml).
Thoughts would be appreciated!
<!-- HAVE THIS -->
<?xml version="1.0" encoding="UTF-8"?><br/>
<Friends xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance http://www.w3.org/2001/XMLSchema-instance " xsi:noNamespaceSchemaLocation="C:docsFriend.xsd <br/>
<PersonalFriend><br/>
<City>Chicago</City><br/>
<State>Illinois</State><br/>
<Country>USA</Country><br/>
<LastName>John</LastName><br/>
<MiddleName>J</MiddleName><br/>
<FirstName>Doe</FirstName><br/>
</PersonalFriend><br/>
<FacebookFriend><br/>
<City>San Francisco</City><br/>
<State>Califonia</State><br/>
<Country>USA</Country><br/>
<FacebookName>Bookworm</FacebookName><br/>
</FacebookFriend><br/>
</Friends>
<!-- WOULD LIKE THIS --><br/>
<?xml version="1.0" encoding="UTF-8"?><br/>
<Friends xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance http://www.w3.org/2001/XMLSchema-instance " xsi:noNamespaceSchemaLocation="C:docsFriend.xsd <br/>
<PersonalFriend><br/>
<LastName>John</LastName><br/>
<MiddleName>J</MiddleName><br/>
<FirstName>Doe</FirstName><br/>
<City>Chicago</City><br/>
<State>Illinois</State><br/>
<Country>USA</Country><br/>
</PersonalFriend><br/>
<FacebookFriend><br/>
<FacebookName>Bookworm</FacebookName><br/>
<City>San Francisco</City><br/>
<State>Califonia</State><br/>
<Country>USA</Country><br/>
</FacebookFriend><br/>
</Friends>
<!-- HERES THE XSD SCHEMA -->
<?xml version="1.0" encoding="UTF-8"?><br/>
<xs:schema xmlns:xs=" http://www.w3.org/2001/XMLSchema http://www.w3.org/2001/XMLSchema " elementFormDefault="qualified" attributeFormDefault="unqualified <br/>
<xs:element name="Friends" type="FriendsType"/><br/>
<xs:complexType name="FriendsType <br/>
<xs:sequence><br/>
<xs:element name="PersonalFriend" type="PersonalFriendType" minOccurs="1" maxOccurs="unbounded"/><br/>
<xs:element name="FacebookFriend" type="FacebookFriendType" minOccurs="1" maxOccurs="unbounded"/><br/>
</xs:sequence><br/>
</xs:complexType><br/>
<xs:complexType name="FriendType" abstract="true <br/>
<xs:sequence><br/>
<xs:element name="City" type="xs:string" minOccurs="1" maxOccurs="1"/><br/>
<xs:element name="State" type="xs:string" minOccurs="1" maxOccurs="1"/><br/>
<xs:element name="Country" type="xs:string" minOccurs="1" maxOccurs="1"/><br/>
</xs:sequence><br/>
</xs:complexType><br/>
<xs:complexType name="PersonalFriendType <br/>
<xs:complexContent><br/>
<xs:extension base="FriendType <br/>
<xs:sequence><br/>
<xs:element name="LastName" type="xs:string" minOccurs="1" maxOccurs="1"/><br/>
<xs:element name="MiddleName" type="xs:string" minOccurs="1" maxOccurs="1"/><br/>
<xs:element name="FirstName" type="xs:string" minOccurs="1" maxOccurs="1"/><br/>
</xs:sequence><br/>
</xs:extension><br/>
</xs:complexContent><br/>
</xs:complexType><br/>
<xs:complexType name="FacebookFriendType <br/>
<xs:complexContent><br/>
<xs:extension base="FriendType <br/>
<xs:sequence><br/>
<xs:element name="FacebookName" type="xs:string" minOccurs="1" maxOccurs="1"/><br/>
</xs:sequence><br/>
</xs:extension><br/>
</xs:complexContent><br/>
</xs:complexType><br/>
</xs:schema>

View the full article
 
Back
Top