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/