468,267 Members | 1,828 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,267 developers. It's quick & easy.

xml inheritance random order

Hi,

I am trying to use XML inheritance to define a base class and derived
class that can have elements appear in any order. from what i've read,
i can only extend the base class in sequential order. does anyone know
how to do this? for example, if i want to allow both of these:

<employee>
<firstname>larry</firstname>
<lastname>jones</lastname>
</employee>

<employee>
<lastname>smith</lastname>
<firstname>mary</firstname>
<city>new york</city>
</employee>

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="employee" type="fullpersoninfo"/>
<xs:complexType name="personinfo">
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
</xs:sequence>
</xs:complexType><xs:complexType name="fullpersoninfo">
<xs:complexContent>
<xs:extension base="personinfo">
<xs:sequence>
<xs:element name="address" type="xs:string"/>
<xs:element name="city" type="xs:string"/>
<xs:element name="country" type="xs:string"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>

May 10 '06 #1
4 1052
Hi,

A schema that validates both your instances is below. It adds also the
lastname, firstname sequence with a choice with the initial firstname,
lastname sequence and makes the elements added in the extended type
optional:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="employee" type="fullpersoninfo"/>
<xs:complexType name="personinfo">
<xs:choice>
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
</xs:sequence>
<xs:sequence>
<xs:element name="lastname" type="xs:string"/>
<xs:element name="firstname" type="xs:string"/>
</xs:sequence>
</xs:choice>
</xs:complexType>
<xs:complexType name="fullpersoninfo">
<xs:complexContent>
<xs:extension base="personinfo">
<xs:sequence>
<xs:element name="address" type="xs:string" minOccurs="0"/>
<xs:element name="city" type="xs:string" minOccurs="0"/>
<xs:element name="country" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

May 10 '06 #2
hi,

that would work, however my base class has 100+ elements, which can be
in any order and they are all optional. the derived class's elements
are also all optional and can be in any order as well. i dont believe
the above solution will work for my situation. any thoughts? thanks
for your response!

May 10 '06 #3
Give up and declare the base element's content as "any"?

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
May 10 '06 #4
hi,

i tried that, but for some reason my xml keeps coming up as invalid
unless i declare the objects as xs:sequence, and that wont work for me.

thanks anyway.

May 10 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Rahul Anand | last post: by
5 posts views Thread by Christopher Brandsdal | last post: by
7 posts views Thread by Jean-Francois.Doyon | last post: by
14 posts views Thread by Steve Jorgensen | last post: by
2 posts views Thread by Arnau Rebassa | last post: by
5 posts views Thread by muskie | last post: by
11 posts views Thread by George Sakkis | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.