Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Strict order of elements being a pain

Reply
Thread Tools

Strict order of elements being a pain

 
 
Christine McGavran
Guest
Posts: n/a
 
      01-31-2004
To continue a previous thread, sort of...

I have defined a schema for describing a windows-style user interface. My
application correctly parses and uses that schema. I'm now trying to get
that schema to be legal, so that if I threw my UI.xml and UISchema.xml at a
validator it would succeed.

I have just learned that the order of elements is important, that is if you
define a schema with element a followed by element b, then in the xml they
must also be in that order. That turns out to be very inconvenient for me,
as the order is important for my UI system. I'm curious why this order is
seen as an important thing, and again looking for suggestions on how to do
things more legally in my situation.

A rough example:

<complexType name="Window">
<sequence>
<element name="align" type="ui:Align" minOccurs="0" maxOccurs="1"
/>
<element name="size" type=ui:Size" minOccurs="0" maxOccurs="1" />
<element name="children" minOccurs="0" maxOccurs="1">
<complexType>
<sequence>
<element name="redWindow" type="ui:Window"
minOccurs="0" maxOccurs="unbounded" />
<element name="blueWindow" type="ui:Window"
minOccurs="0" maxOccurs="unbounded" />
</sequence>
</complexType>
</element>
</sequence>
</complexType>
<element name="window" type="ui:Window" />


I would like my xml to be able to create a window with children windows from
left to right being red blue red. For example:

<window>
<size x="30" y="10" />
<children>
<redWindow>
<align left="parentLeft" top="parentTop" bottom="parentBottom"
/>
<size x="10" />
</redWindow>
<blueWindow>
<align left="prevRight" top="parentTop" bottom="parentBottom" />
<size x="10" />
</blueWindow>
<redWindow>
<align left="prevRight" top="parentTop" bottom="parentBottom" />
<size x="10" />
</redWindow>
</children>
</window>

This xml will not validate because redWindow is not allowed to follow
blueWindow. My application, however, parses and uses this xml just fine. You
might be able to think of a few ways around this simple case, but when the
window contents get complex, being able to enforce order becomes very handy.
The only other alternative I can think of is to put some GUID on each window
to use for ID in alignment, which seems like a pain for the user.

Thanks in advance,
Christine


 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      01-31-2004


Christine McGavran wrote:


> I have defined a schema for describing a windows-style user interface. My
> application correctly parses and uses that schema. I'm now trying to get
> that schema to be legal, so that if I threw my UI.xml and UISchema.xml at a
> validator it would succeed.
>
> I have just learned that the order of elements is important, that is if you
> define a schema with element a followed by element b, then in the xml they
> must also be in that order. That turns out to be very inconvenient for me,
> as the order is important for my UI system. I'm curious why this order is
> seen as an important thing, and again looking for suggestions on how to do
> things more legally in my situation.


Nobody forces you to define a schema at all to use XML, and nobody
forces you to use a sequence in a type definition. There are other ways
to define a complex type than using a sequence, for instance choice or
all. Thus if the order of elements doesn't matter to you then consider a
different type definition.
--

Martin Honnen
http://JavaScript.FAQTs.com/

 
Reply With Quote
 
 
 
 
Christine McGavran
Guest
Posts: n/a
 
      02-01-2004
> Nobody forces you to define a schema at all to use XML

No, but I would like to be able to for a few reasons. One is customers are
given a formal documentation of our scripting syntax, and a way to test if
their scripts are not valid. Another is the DevStudio xml editor behaves
nicely if you have a schema.

> There are other ways
> to define a complex type than using a sequence, for instance choice or
> all. Thus if the order of elements doesn't matter to you then consider a
> different type definition.


Choice requires that only one of the elements occur. That doesn't work, as
it would not allow me to have both a redWindow and a blueWindow as a child.
All requires that no element may occur more than once, which means I could
have redWindow and blueWindow in either order, but I could not have two
redWindows. Both of those restrictions are unacceptable in my situation. Or
am I missing something?


 
Reply With Quote
 
Oliver Bonten
Guest
Posts: n/a
 
      02-01-2004
Christine,

On Sun, 01 Feb 2004 00:47:45 +0000, Christine McGavran wrote:

> Choice requires that only one of the elements occur. That doesn't work, as
> it would not allow me to have both a redWindow and a blueWindow as a child.
> All requires that no element may occur more than once, which means I could
> have redWindow and blueWindow in either order, but I could not have two
> redWindows. Both of those restrictions are unacceptable in my situation. Or
> am I missing something?


yes, you are missing something. You can give a repetition count for the
Choice group. I don't know how to say this in XML Schema, but in a DTD it
would be (redWindow|blueWindow)+ (as opposed to (redWindow|blueWindow),
which is just the Choice), and this construction can be expressed in XML
Schema as well.

Oliver
 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      02-01-2004


Christine McGavran wrote:


>>There are other ways
>>to define a complex type than using a sequence, for instance choice or
>>all. Thus if the order of elements doesn't matter to you then consider a
>>different type definition.

>
>
> Choice requires that only one of the elements occur. That doesn't work, as
> it would not allow me to have both a redWindow and a blueWindow as a child.
> All requires that no element may occur more than once, which means I could
> have redWindow and blueWindow in either order, but I could not have two
> redWindows. Both of those restrictions are unacceptable in my situation. Or
> am I missing something?


Yes, you are missing that you can give min and/or maxOccurs attributes
to schema elements, that you can nest a sequence in a choice etc. That
gives you a lot of ways to express how the content should look.
For instance to allow any number of blueWindow and redWindow child
elements in any order you could use a schema alike

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlnss="http://www.w3.org/2001/XMLSchema">

<xs:element name="windows">
<xs:complexType>
<xs:sequence>
<xs:element ref="window" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:element name="window">
<xs:complexType>
<xs:sequence>
<xs:element name="children">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="redWindow" />
<xs:element name="blueWindow" />
</xs:choice>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>

</xs:schema>

As the type of the <children> element is a choice of redWindow or
blueWindow that can occur zero to unbounded times you can put in any
combination of <redWindow> and <blueWindow> child elements.

--

Martin Honnen
http://JavaScript.FAQTs.com/

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
HEEEEEEEEEEELP!!!!!!!!!!: Hipcrime is being a pain in the @$$!!!!!! Radium Computer Support 12 09-17-2007 11:12 PM
Chronic Back Pain Michael MCSD 0 04-02-2006 02:43 AM
Chronic Back Pain Michael MCSE 0 04-02-2006 02:43 AM
Modelsim error: Cannot read output pain Olaf Petzold VHDL 12 12-23-2005 09:15 PM
xhtml strict is being very stict why? Christopher R HTML 13 10-01-2003 07:17 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57