473,804 Members | 3,349 Online
Bytes | Software Development & Data Engineering Community
+ 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:complexTy pe name="BookType" >
<xs:choice maxOccurs="unbo unded">
<xs:element ref="Title"/>
<xs:element ref="Author"/>
<xs:element ref="ISBN"/>
<xs:element ref="Descriptio n"/>
</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 3834
Kevin,

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

Hope that helps,
Priscilla

-----------------------------------------------------
Priscilla Walmsley pr*******@walms ley.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*********@yah oo.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*********@yah oo.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
2151
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
1306
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 generated names. I should probably just get over it, but anyhow... Let's say I am writing a file for creating a database. Say ... -- schematest CREATE SEQUENCE foo_id_seq; CREATE TABLE foo(
1
4338
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" encoding="utf-8"?>| <customers xmlns="http://tempuri.org/customers.xsd"> <Customer ID="1000"> <FirstName>Greg</FirstName>
2
9453
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. Actually, second time I do a deserialization, the data from XML is fed directly to an object. The problem I am experiencing is the error at the second reading attempt, and error description implies that reader is winded to the end of the XML and...
1
2978
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. The problem I am having is that the validation event fires for each node in the xml. It seems to be completely ignoring the schema that I have used. I'm wondering if I need to do something extra to tell the xml which schema to use.
3
6061
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 errors saying what happened and where...... is it possible to do that ? for eg. if the Attribute is missing or invalid in the following element <Watch ID="999d999">
1
1747
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 that is handed off to my code. I've been able to figure out how to get the data type by reading through a validating reader, but I can't seem to find an easy way to get this when using XPath expressions. The process I have is as follows: 1....
0
1837
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 performs modifications to any data, and "Fields" inside the tag that outline the changes that were made. Applications in the flow of the system read in these XML files and will "overlay" these tags in order to obtain data for all fields that were...
9
3023
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> <binaryobject3></binaryobject3>
0
9576
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10310
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7613
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6847
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5515
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4291
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 we have to send another system
2
3809
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2983
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.