XML-Schema: Problems with Restricted XPath in Selector of Unique

  • Thread starter Torsten Munkelt
  • Start date
T

Torsten Munkelt

Hi,

I want to write an XML-schema saying that this document [1]

<root>
<edge type="special">
<target type="one"/>
</edge>
<edge type="special">
<target type="one"/>
</edge>
</root>

is not valid
because there must not be more than one edge-element
- with a type 'special' and
- with a target of the same type (in that case 'one').

This document [2]

<root>
<edge type="special">
<target type="one"/>
</edge>
<edge type="normal">
<target type="one"/>
</edge>
</root>

should be valid because there is only one edge with type special
and a target of type one.

This document [3]

<root>
<edge type="special">
<target type="one"/>
</edge>
<edge type="special">
<target type="two"/>
</edge>
</root>

should also be valid because there are two special edges
but they have different target types.

I try validation using this xml-schema:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs=http://www.w3.org/2001/XMLSchema
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:element name="root">
<xs:complexType>
<xs:sequence maxOccurs="unbounded">
<xs:element name="edge" type="edge"/>
</xs:sequence>
</xs:complexType>

<!-- WHY DOESN'T WORK THE FOLLOWING -->
<xs:unique name="special-uniqueness">
<xs:selector xpath="edge[@type='special']/target"/>
<xs:field xpath="@type"/>
</xs:unique>

</xs:element>
<xs:complexType name="edge">
<xs:sequence>
<xs:element name="target" type="target"
minOccurs="1" maxOccurs="1"/>
</xs:sequence>
<xs:attribute name="type" type="xs:string" use="required"/>
</xs:complexType>
<xs:complexType name="target">
<xs:attribute name="type" type="xs:string" use="required"/>
</xs:complexType>
</xs:schema>

but I do not succeed: The XPath-expression in the selector of the
unique-element below the XML-comment is not allowed in restricted
XPath syntax.

Does anybody has an idea how to write an XML-schema saying the
document one is not valid but the documents two and three are
valid (given the above criteria)?

Thank you very much for your answers in advance.

Best regards - Torsten
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top