473,396 Members | 1,933 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 1199
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Rahul Anand | last post by:
Hi all, I am trying to fetch 5 records, randomly picked and in random order from a MySQL table (MySQL version > 3.23). I wrote my SQL Query as SELECT name,id FROM tablename WHERE active =...
5
by: Christopher Brandsdal | last post by:
Hi! I'm not sure, but this might be a question not right for this group. Problem: I have a sql statement that selects all rows with a sertain criteria, an display it on a page. What I need...
7
by: Jean-Francois.Doyon | last post by:
Hello, I'm trying to retrieve a limited number of random rows, and order them by a column, and am not having any luck with that last part: SELECT * FROM tablename ORDER BY random(), id LIMIT...
14
by: Steve Jorgensen | last post by:
Recently, I tried and did a poor job explaining an idea I've had for handling a particular case of implementation inheritance that would be easy and obvious in a fully OOP language, but is not at...
2
by: Arnau Rebassa | last post by:
Hi everybody, I'm doing the following query: select * from messages order by random() limit 1; in the table messages I have more than 200 messages and a lot of times, the message retrieved...
48
by: Jimmy | last post by:
thanks to everyone that helped, unfortunately the code samples people gave me don't work. here is what i have so far: <% Dim oConn, oRS, randNum Randomize() randNum = (CInt(1000 * Rnd) + 1) *...
12
by: Pascal | last post by:
hello and soory for my english here is the query :"how to split a string in a random way" I try my first shot in vb 2005 express and would like to split a number in several pieces in a random way...
5
by: muskie | last post by:
I've looked through as many posts about this as possible, but all end with no resolution. I simply need records from a table in random order, and I will be calling this recordset in a SQL...
11
by: George Sakkis | last post by:
I have a situation where one class can be customized with several orthogonal options. Currently this is implemented with (multiple) inheritance but this leads to combinatorial explosion of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.