468,133 Members | 1,379 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,133 developers. It's quick & easy.

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 1280


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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Mark Jerde | last post: by
1 post views Thread by Lian Liming | last post: by
1 post views Thread by Ganesh Muthuvelu | last post: by
3 posts views Thread by Eric Lilja | last post: by
1 post views Thread by gcdp | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.