473,395 Members | 1,689 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,395 software developers and data experts.

Strict order of elements being a pain

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
Jul 20 '05 #1
4 3044


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/

Jul 20 '05 #2
> 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?
Jul 20 '05 #3
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
Jul 20 '05 #4


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 xmlns:xs="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/

Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Jonny | last post by:
How can you validate Javascript generated HTML for XHTML 1.0 strict compliance? To avoid the "<" and "&" problem, all inline scripts MUST be enclosed with either: <!-- script --> Looked down...
11
by: Woolly Mittens | last post by:
I tried validating my gallery page using your validator. http://validator.w3.org/check?uri=http%3A%2F%2Fwww.woollymittens.nl%2Fcontent%2Fgallery%2Findex.asp To my surprise it informed me that...
41
by: CMAR | last post by:
What are the pluses and minuses of constructing and validating between XHTML Transitional vs. HTLM 4.01 Strict Thanks, CMA
2
by: Brian Idzik | last post by:
I've successfully setup a xhtml 1.0 strict page with Mozilla & Netscape to display links in a toolbar into an internal <div id='content'> within the same document. The toolbar uses some...
13
by: Kieran | last post by:
I am designing a content management system and I want to make sure all pages entered into it's database by users are using valid HTML. I have designed the system to use HTML 4.01 Transitional...
6
by: Brett | last post by:
I find there is more casting required in C# than VB.NET. If Option Strict/Explicit is turned on, will this basically create the same environment as C# - uppercase, more casting required, must...
50
by: Shadow Lynx | last post by:
Consider this simple HTML: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 STRICT//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head>...
22
by: Vijay | last post by:
With the option strict On set..... Dim fs As FileStream = File.OpenRead(strFile) With fs Dim buffer(fs.Length) As Byte ' <--- Option Strict On disallows implicit conversions from 'Long' to...
92
by: Erwin Moller | last post by:
Hi group, I encoutered page validation error, but I don't know a way around. The page has the following doctype: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

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.