XML Schema <xs:unique/> scope

Discussion in 'XML' started by cedric.louyot@gmail.com, Feb 14, 2007.

  1. Guest

    Hi,

    I've written a schema that looks like :

    <xs:schema>
    <xs:complexType name="myType">
    <xs:sequence>
    <xs:element name="e1" type="T1" maxOccurs="unbounded"/>
    <xs:element name="e2" type="xs:string"/>
    </xs:sequence>
    </xs:complexType>
    <xs:complexType name="T1">
    <xs:sequence>
    <xs:element name="e3" type="T3" maxOccurs="unbounded"/>
    <xs:element name="e4" type="xs:string"/>
    </xs:sequence>
    </xs:complexType>
    <xs:complexType name="T3">
    <xs:sequence>
    <xs:element name="name" type="xs:string" maxOccurs="unbounded"/>
    <xs:element name="adress" type="xs:string"/>
    </xs:sequence>
    </xs:complexType>
    <xs:element name="myElement" type="myType">
    <xs:unique name="uniqueName>
    <xs:selector xpath="./e1/e3"/>
    <xs:field xpath="name"/>
    </xs:unique>
    </xs:element>
    </xs:schema>

    The <xs:unique/> element garantees there is only one element "./e1/e3"
    in my xml file that has a given name. This prevents me from having 2
    elements with the same name in 2 different e1 elements because my
    <xs:unique/> element is in the scope of "myElement". I would like to
    be allowed to name two element e3 with the same name providing they do
    not have the same e1 ancestor. Therefore I have to define my
    <xs:unique/> element in the scope of "myElement/e1" instead of
    "myElement".
    How do I do that given that I want to keep defining all my complex
    types before defining the "myElement" element ? I would like to avoid
    defining more than one <xs:element/> element.

    Thanks,

    Cédric
    , Feb 14, 2007
    #1
    1. Advertising

  2. Hi Cédric,

    writes:

    > <xs:schema>
    > <xs:complexType name="myType">
    > <xs:sequence>
    > <xs:element name="e1" type="T1" maxOccurs="unbounded"/>
    > <xs:element name="e2" type="xs:string"/>
    > </xs:sequence>
    > </xs:complexType>
    > <xs:complexType name="T1">
    > <xs:sequence>
    > <xs:element name="e3" type="T3" maxOccurs="unbounded"/>
    > <xs:element name="e4" type="xs:string"/>
    > </xs:sequence>
    > </xs:complexType>
    > <xs:complexType name="T3">
    > <xs:sequence>
    > <xs:element name="name" type="xs:string" maxOccurs="unbounded"/>
    > <xs:element name="adress" type="xs:string"/>
    > </xs:sequence>
    > </xs:complexType>
    > <xs:element name="myElement" type="myType">
    > <xs:unique name="uniqueName>
    > <xs:selector xpath="./e1/e3"/>
    > <xs:field xpath="name"/>
    > </xs:unique>
    > </xs:element>
    > </xs:schema>
    >
    > Therefore I have to define my <xs:unique/> element in the scope
    > of "myElement/e1" instead of "myElement".
    >
    > How do I do that given that I want to keep defining all my complex
    > types before defining the "myElement" element ? I would like to avoid
    > defining more than one <xs:element/> element.


    You would just add unique to the e1 element declaration:

    <xs:complexType name="myType">
    <xs:sequence>
    <xs:element name="e1" type="T1" maxOccurs="unbounded">
    <xs:unique name="uniqueName>
    <xs:selector xpath="e3"/>
    <xs:field xpath="name"/>
    </xs:unique>
    </xs:element>
    <xs:element name="e2" type="xs:string"/>
    </xs:sequence>
    <xs:complexType>


    hth,
    -boris


    --
    Boris Kolpackov
    Code Synthesis Tools CC
    http://www.codesynthesis.com
    Open-Source, Cross-Platform C++ XML Data Binding
    Boris Kolpackov, Feb 14, 2007
    #2
    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,495
    Markus
    Nov 23, 2005
  2. Fred Smith
    Replies:
    1
    Views:
    922
    Martin Honnen
    Feb 5, 2004
  3. Hari Om
    Replies:
    1
    Views:
    449
    Martin SChukrazy
    Mar 2, 2004
  4. Stanimir Stamenkov
    Replies:
    3
    Views:
    1,166
    Stanimir Stamenkov
    Apr 25, 2005
  5. Replies:
    3
    Views:
    2,786
Loading...

Share This Page