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

Discussion in 'XML' started by Torsten Munkelt, Jan 4, 2007.

  1. 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
     
    Torsten Munkelt, Jan 4, 2007
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Markus
    Replies:
    1
    Views:
    1,665
    Markus
    Nov 23, 2005
  2. Fred Smith
    Replies:
    1
    Views:
    998
    Martin Honnen
    Feb 5, 2004
  3. Stanimir Stamenkov
    Replies:
    3
    Views:
    1,329
    Stanimir Stamenkov
    Apr 25, 2005
  4. Replies:
    3
    Views:
    3,175
  5. Kenneth McDonald
    Replies:
    6
    Views:
    1,816
    Mark Thomas
    Dec 30, 2008
Loading...

Share This Page