472,958 Members | 2,170 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Simple XML Schema problem


If there is a document like this:

<Configurations>

<Configuration default="true">
...
</Configuration>

<Configuration>
...
</Configuration>

...

</Configurations>

How can I ensure with a schema that only 0 or 1 <Configuration>
element has the "default" attribute set to "true"?

I suppose this is a fairly common problem and someone somewhere must
have gone through this already. Appreciate any hints.

Thanks,

Maxim
Jul 20 '05 #1
1 1381


Maxim wrote:
If there is a document like this:

<Configurations>

<Configuration default="true">
...
</Configuration>

<Configuration>
...
</Configuration>

...

</Configurations>

How can I ensure with a schema that only 0 or 1 <Configuration>
element has the "default" attribute set to "true"?

I suppose this is a fairly common problem and someone somewhere must
have gone through this already. Appreciate any hints.


You could define the type of the attribute as xs:boolean so that it can
only have the values true or false and then you could specify a
uniqueness constraint for <Configuration> elements regarding that attribute:

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

<xs:element name="Configurations">
<xs:complexType>
<xs:sequence>
<xs:element ref="Configuration" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
<xs:unique name="uniqueConfigDefault">
<xs:selector xpath="Configuration" />
<xs:field xpath="@default" />
</xs:unique>
</xs:element>

<xs:element name="Configuration">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="default" type="xs:boolean" use="optional" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>

</xs:schema>

That way one <Configuration> can have the default="true" attribute and
others can simply not specify the attribute as you have in your example.

--

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

Jul 20 '05 #2

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

Similar topics

0
by: mjcsfo | last post by:
I can't seem to find a reference nor any helpful threads on this topic. I've gotten the following error in two circumstances: 1. A complex type has nested within it another complex type, in the...
6
by: Mark Jerde | last post by:
We have developed about 80 XML documents, each probably 150 lines long, that are all supposed to conform to a schema. My understanding is the way to show that an XML document conforms to a schema...
1
by: James R | last post by:
Ok, I'm new at this and learning as I go, but under extreme pressure from work.. So many bugs and little tricky obsticals have got me very far behind, and this is the latest.. I made a simple...
1
by: Lian Liming | last post by:
Hi all, I want to write a schema for the following example xml file: <Items> <ItemA>hehe</ItemB> <ItemB>haha</ItemB> </Items> So far as my knowledge about xml schema, I can write the...
1
by: Chris Lieb | last post by:
I am new to XML Schema and am running into a bit of a snag. I have defined an XML-based scripting language for an updater program that I am working on. I would like to make a schema for this...
1
by: Ganesh Muthuvelu | last post by:
Hello, I have a simple schema as shown below. When I validate it, I get the error "Type 'http://www.w3.org/2001/XMLSchema:emptype' is not declared. An error occurred at , (6, 12)." ...
2
by: smachin1000 | last post by:
Hi All, In the sample schema & document below, I'd like the attribute "name" to be unique for all function elements under function_list. The tools I'm using (XML Spy and xmllint) all validate...
3
by: Eric Lilja | last post by:
Hello, this is an xml-file with a nested DTD. It validates, test-1- with-dtd.xml: <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE persons > <persons> <person name="Eric Lilja" /> </persons>
2
by: olympus_mons | last post by:
Hi, I'm just discovering the power of xsd.exe, so maybe I'm doing something wrong. schema files describing requests and responses. So there is an extra xsd file for each response and each...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.