unique integer id as attribute

Discussion in 'XML' started by Mario, Dec 8, 2004.

  1. Mario

    Mario Guest

    Hi,

    I want to use a unique ID attribute, which should be an integer value.
    I tried the solution below with xpath, but the xml seems to be valid,
    even if there are two equal ids. Any idea why?


    My XSD
    ---------------------------------------------------------------------
    <xs:element name="sample">
    <xs:complexType>
    <xs:choice maxOccurs="unbounded">
    <xs:element name="one" maxOccurs="10">
    <xs:complexType>
    <xs:attribute name="anothertxt" type="xs:string"/>
    <xs:attribute name="sequenceid" type="xs:integer" use="required"/>
    </xs:complexType>
    </xs:element>
    <xs:element name="two" maxOccurs="10">
    <xs:complexType>
    <xs:attribute name="sequenceid" type="xs:integer" use="required"/>
    </xs:complexType>
    </xs:element>
    <xs:element name="three" maxOccurs="10">
    <xs:complexType>
    <xs:attribute name="sequenceid" type="xs:integer" use="required"/>
    </xs:complexType>
    </xs:element>
    </xs:choice>
    </xs:complexType>
    <xs:key name="seqid">
    <xs:selector xpath=".//sample"/>
    <xs:field xpath="@sequenceid"/>
    </xs:key>
    </xs:element>
    ---------------------------------------------------------------------

    My XML
    ---------------------------------------------------------------------
    <sample xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="sample.xsd">
    <one sequenceid="1"/>
    <one sequenceid="2"/>
    <two sequenceid="3"/>
    <two sequenceid="3"/>
    </sample>
    ---------------------------------------------------------------------
    Mario, Dec 8, 2004
    #1
    1. Advertising

  2. Mario wrote:


    > I want to use a unique ID attribute, which should be an integer value.
    > I tried the solution below with xpath, but the xml seems to be valid,
    > even if there are two equal ids. Any idea why?
    >
    >
    > My XSD
    > ---------------------------------------------------------------------
    > <xs:element name="sample">


    > <xs:key name="seqid">
    > <xs:selector xpath=".//sample"/>


    Why the path to sample if the sequenceid attribute is on the other
    elements, e.g. one or two?

    > <xs:field xpath="@sequenceid"/>


    > My XML
    > ---------------------------------------------------------------------
    > <sample xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    > xsi:noNamespaceSchemaLocation="sample.xsd">
    > <one sequenceid="1"/>
    > <one sequenceid="2"/>
    > <two sequenceid="3"/>
    > <two sequenceid="3"/>
    > </sample>




    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Dec 8, 2004
    #2
    1. Advertising

  3. Mario

    Mario Guest

    I thought this might be the only possibility to get the sequence ID
    unique for all element-attributes below <sample>... is this wrong?

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Mario, Dec 8, 2004
    #3
  4. Mario wrote:

    > I thought this might be the only possibility to get the sequence ID
    > unique for all element-attributes below <sample>... is this wrong?


    You should be able to use
    <xs:selector xpath=".//*">
    to match any descendant element, at least that is my current reading of
    the XML schema specification. Try that.
    It should also be possible to list alternatives e.g.
    <xs:selector xpath="one | two | three">
    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Dec 8, 2004
    #4
  5. Mario

    Mario Guest

    Hey cool, that way it rocks. Thx a lot!!

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Mario, Dec 8, 2004
    #5
    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. James J. Foster
    Replies:
    0
    Views:
    516
    James J. Foster
    Aug 7, 2003
  2. Christopher Brian  Colohan

    Unique Integer Types -- a useful C++ trick

    Christopher Brian Colohan, Nov 19, 2004, in forum: C++
    Replies:
    2
    Views:
    500
    Jonathan Turkanis
    Nov 19, 2004
  3. Replies:
    2
    Views:
    7,159
  4. ToshiBoy
    Replies:
    6
    Views:
    824
    ToshiBoy
    Aug 12, 2008
  5. Token Type
    Replies:
    9
    Views:
    335
    Chris Angelico
    Sep 9, 2012
Loading...

Share This Page