Re: make a unbroken sequence of id attribute with XSD

Discussion in 'XML' started by eephyne, Mar 18, 2011.

  1. eephyne

    eephyne Guest

    i have already set a unique tag to define id with only number. But i guess i will have to check programaticaly the unbroken sequence of number :/

    thanks for the answer
     
    eephyne, Mar 18, 2011
    #1
    1. Advertising

  2. eephyne wrote:
    > i have already set a unique tag to define id with only number. But i guess i will have to check programaticaly the unbroken sequence of number :/


    Here is an example of how you can check the constraint with Xerces 2.11
    Beta supporting the working draft of the W3C schema language 2.0 and an
    assertion:


    <xs:schema
    xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <xs:element name="root">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="object-list" maxOccurs="unbounded">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="object" maxOccurs="unbounded">
    <xs:complexType>
    <xs:attribute name="id" type="xs:integer"/>
    </xs:complexType>
    </xs:element>
    </xs:sequence>
    <xs:assert test="every $pos in 0 to max(object/@id)
    satisfies exists(object[@id = $pos])"/>
    </xs:complexType>
    <xs:unique name="unique-id">
    <xs:selector xpath="object"/>
    <xs:field xpath="@id"/>
    </xs:unique>
    </xs:element>
    </xs:sequence>
    </xs:complexType>
    </xs:element>

    </xs:schema>

    Then for the sample document

    <root>
    <object-list>
    <object id="0" />
    <object id="2" />
    <object id="1" />
    </object-list>
    <object-list>
    <object id="0" />
    <object id="2" />
    <object id="3" />
    </object-list>
    </root>

    you will get an error as follows:

    [Error] test2011031802.xml:11:17: cvc-assertion.3.13.4.1: Assertion
    evaluation (
    'every $pos in 0 to max(object/@id) satisfies exists(object[@id =
    $pos])') for element 'object-list' with type '#anonymous' did not succeed.


    --

    Martin Honnen
    http://msmvps.com/blogs/martin_honnen/
     
    Martin Honnen, Mar 18, 2011
    #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. eephyne
    Replies:
    2
    Views:
    938
    Alain Ketterlin
    Mar 18, 2011
  2. eephyne
    Replies:
    2
    Views:
    934
    Jongware
    Mar 21, 2011
  3. eephyne
    Replies:
    1
    Views:
    895
    Peter Flynn
    Mar 21, 2011
  4. eephyne
    Replies:
    2
    Views:
    931
    Joe Kesselman
    Mar 24, 2011
  5. eephyne
    Replies:
    1
    Views:
    886
    Jongware
    Mar 24, 2011
Loading...

Share This Page