unique integer id as attribute

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mario

    unique integer id as attribute

    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="unbo unded">
    <xs:element name="one" maxOccurs="10">
    <xs:complexType >
    <xs:attribute name="anothertx t" type="xs:string "/>
    <xs:attribute name="sequencei d" type="xs:intege r" use="required"/>
    </xs:complexType>
    </xs:element>
    <xs:element name="two" maxOccurs="10">
    <xs:complexType >
    <xs:attribute name="sequencei d" type="xs:intege r" use="required"/>
    </xs:complexType>
    </xs:element>
    <xs:element name="three" maxOccurs="10">
    <xs:complexType >
    <xs:attribute name="sequencei d" type="xs:intege r" use="required"/>
    </xs:complexType>
    </xs:element>
    </xs:choice>
    </xs:complexType>
    <xs:key name="seqid">
    <xs:selector xpath=".//sample"/>
    <xs:field xpath="@sequenc eid"/>
    </xs:key>
    </xs:element>
    ---------------------------------------------------------------------

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

    #2
    Re: unique integer id as attribute



    Mario wrote:

    [color=blue]
    > 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">[/color]
    [color=blue]
    > <xs:key name="seqid">
    > <xs:selector xpath=".//sample"/>[/color]

    Why the path to sample if the sequenceid attribute is on the other
    elements, e.g. one or two?
    [color=blue]
    > <xs:field xpath="@sequenc eid"/>[/color]
    [color=blue]
    > My XML
    > ---------------------------------------------------------------------
    > <sample xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
    > xsi:noNamespace SchemaLocation= "sample.xsd ">
    > <one sequenceid="1"/>
    > <one sequenceid="2"/>
    > <two sequenceid="3"/>
    > <two sequenceid="3"/>
    > </sample>[/color]



    --

    Martin Honnen

    Comment

    • Mario

      #3
      Re: unique integer id as attribute

      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!

      Comment

      • Martin Honnen

        #4
        Re: unique integer id as attribute



        Mario wrote:
        [color=blue]
        > I thought this might be the only possibility to get the sequence ID
        > unique for all element-attributes below <sample>... is this wrong?[/color]

        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

        Comment

        • Mario

          #5
          Re: unique integer id as attribute

          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!

          Comment

          Working...