473,463 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Schema for validating unordered sequences?

Say I have the following XML spec:

<Book>
<Title />
<Author />
<ISBN />
<Description />
</Book>

Title, Author, ISBN and Description may appear in any order. Title,
Author and ISBN must appear exactly once, and Description may appear 0
or 1 times. Thus, the following XML is also valid.

<Book>
<Author />
<ISBN />
<Title />
</Book>

I haven't been working with XML schemas for very long, but from what I
have read it seems that it would be fairly difficult to validate this
type of XML using schemas.

I know how to specify an unordered list where all elements are
optional and unbounded:

<xs:complexType name="BookType">
<xs:choice maxOccurs="unbounded">
<xs:element ref="Title"/>
<xs:element ref="Author"/>
<xs:element ref="ISBN"/>
<xs:element ref="Description"/>
</xs:choice>
</xs:complexType>
<xs:element name="Book" type="BookType" />

However, such a schema permits invalid XML such as this:

<Book>
<Title>
<Title>
</Book>

Using the above schema, I could perform further validation in my code,
but I am wondering if there is a way to do it using schema only. It
seems to me that one of the nice benefits of XML as a structured data
format is that element ordering is not necessarily relevant. In my
example the order of the elements has no semantic meaning, so I would
like authors to be able to not worry about ordering while still
gaining the benefits of validated XML.

Does anyone know how to accomplish this using XML Schemas?

Thanks,
Kevin Campbell
Jul 20 '05 #1
3 3814
Kevin,

Use xs:all instead of xs:choice. That should give you what you need.

Hope that helps,
Priscilla

-----------------------------------------------------
Priscilla Walmsley pr*******@walmsley.com
Author, Definitive XML Schema (Prentice Hall PTR)
-----------------------------------------------------
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #2
kc*********@yahoo.com (Kevin Campbell) writes:
... It
seems to me that one of the nice benefits of XML as a structured data
format is that element ordering is not necessarily relevant. In my
example the order of the elements has no semantic meaning, so I would
like authors to be able to not worry about ordering while still
gaining the benefits of validated XML.
If there is no significance attached to the order of
the elements, then why not specify a fixed order? Otherwise
you end up with authors trying to understand or create a
subtle semantic difference between

<Book>
<Title />
<Author />
<ISBN />
<Description />
</Book>

and

<Book>
<Author />
<Title />
<ISBN />
<Description />
</Book>
Does anyone know how to accomplish this using XML Schemas?


As Priscilla Walmsley has already pointed out, the
xsd:all construct does exactly what you say you want.

-C. M. Sperberg-McQueen
Jul 20 '05 #3
cm****@acm.org (C. M. Sperberg-McQueen) wrote in message news:<m2************@acm.org>...
kc*********@yahoo.com (Kevin Campbell) writes:

As Priscilla Walmsley has already pointed out, the
xsd:all construct does exactly what you say you want.

-C. M. Sperberg-McQueen


I thought it would be something simple! Thanks for the help folks. I
guess I was stuck on that "all" name, and forgot I could still use
minOccurs="0" on some of them.

Thanks again,
Kevin
Jul 20 '05 #4

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

Similar topics

1
by: RC | last post by:
I know DTD (Document Type Definition) is supported by Netscape/Firefox and IE. But I typed some examples from http://www.w3schools.com/schema/default.asp Seems no effect on those browsers.
0
by: Lee Harr | last post by:
I am used to creating sequences separately and using them for default values instead of using the serial type. I am not sure why... but that's the way I have been doing it. Maybe I don't trust the...
1
by: Christian | last post by:
Hi, I load an Xml-file "customers.xml" into a DataSet (works fine) but then how do I validate it against a schema (e.g. customers.xsd) ? my customers.xml: <?xml version="1.0"...
2
by: Shone | last post by:
I would like to perform a 2-pass XML reading from a stream. Once using the Validating reader, just to confirm the validity against the schema, and next time to do a reading to extract the data....
1
by: Andy | last post by:
I am having some trouble validating XML using the XmlValidatingReader. I have created some xml and used the visual studio to generate the schema. So I am confident that the xml and schema match. ...
3
by: Shailendra Batham | last post by:
hi guys I need your suggestions / opinion for doing this the right way. I have a XML and a Schema for the same What I want is when its validated against the schema, it should give custom...
1
by: Phil | last post by:
Is there an easy way to get the schema's data type for a XPathNavigator value? I need to be able to determine the data type for the xml value based off of an unknown schema and unknown xml file...
0
by: BC3Tech | last post by:
I'm creating a system that uses XML to store an audit trail of the steps that it has been through in the system. The way the schema is defined, there is a "Tag" for every application that...
9
by: mstilli | last post by:
Hi, I am trying to use schema for server side validation using xerces to catch the validation errors. validating this XML: <Content4> <textarea13></textarea13>...
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.