Uniqueness

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gnomff
    New Member
    • Mar 2008
    • 5

    Uniqueness

    Hi,

    I'm new to creating schemas, and I would like to make an attribute unique. What I currently have looks like this:


    <xs:element name="Tick" type="TickType" maxOccurs="unbo unded" minOccurs="0">
    <xs:unique name="Tick">
    <xs:selector xpath="Tick"/>
    <xs:field xpath="@count"/>
    </xs:unique>
    </xs:element>

    <xs:complexTy pe name="TickType" >
    <xs:attribute name="count" type="xs:int"/>
    </xs:complexType>

    The problem is that files with multiple Ticks with the same count are not failing like they should.

    Example:
    <Tick count="1">

    </Tick>

    <Tick count="1">

    </Tick>

    FYI I'm using xsv.exe to do the validation
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    Move the unique constraint to the parent element containing the Tick elements.

    Comment

    • gnomff
      New Member
      • Mar 2008
      • 5

      #3
      Originally posted by jkmyoung
      Move the unique constraint to the parent element containing the Tick elements.
      Tried it, no luck. I also tried variations on the xpath selector like "./Tick" and "*/Tick" with no success.

      Comment

      • jkmyoung
        Recognized Expert Top Contributor
        • Mar 2006
        • 2057

        #4
        Post the rest of your schema.

        Comment

        • gnomff
          New Member
          • Mar 2008
          • 5

          #5
          <xs:attributeGr oup name="ActionTyp eAttributes">
          <xs:attribute name="type" type="xs:string "/>
          <xs:attribute name="name" type="xs:string "/>
          <xs:attribute name="source" type="xs:int"/>
          <xs:attribute name="destinati on" type="xs:int"/>
          </xs:attributeGro up>

          <xs:complexTy pe name="ActionTyp e">
          <xs:attributeGr oup ref="ActionType Attributes"/>
          </xs:complexType>

          <xs:complexTy pe name="TickType" >
          <xs:sequence>
          <xs:element name="Action" type="ActionTyp e"/>
          </xs:sequence>
          <xs:attribute name="count" type="xs:int"/>
          </xs:complexType>


          <xs:element name="somthing" >
          <xs:complexType >
          <xs:sequence>
          <xs:element name="somthinge lse" type="xs:long"/>
          <xs:element name="Tick" type="TickType" maxOccurs="unbo unded" minOccurs="0">
          <xs:unique name="Tick">
          <xs:selector xpath="Tick"/>
          <xs:field xpath="@count"/>
          </xs:unique>
          </xs:element>
          </xs:sequence>
          </xs:complexType>

          </xs:element>

          Comment

          • gnomff
            New Member
            • Mar 2008
            • 5

            #6
            The file i'm validating looks like this

            <Tick count="1">
            <Action type="FileTrans fer"
            name="/fs/smUmmPeasGood.j pg"
            source="1"
            destination="2" />
            </Tick>

            <Tick count="1">
            <Action type="FileTrans fer"
            name="/fs/smUmmPeasGood.j pg"
            source="1"
            destination="2" />
            </Tick>

            Comment

            • jkmyoung
              Recognized Expert Top Contributor
              • Mar 2006
              • 2057

              #7
              [code=xml]
              <xs:element name="somthing" >
              <xs:complexType >
              <xs:sequence>
              <xs:element name="somthinge lse" type="xs:long"/>
              <xs:element name="Tick" type="TickType" maxOccurs="unbo unded" minOccurs="0"/>
              </xs:sequence>
              </xs:complexType>
              <xs:unique name="Tick">
              <xs:selector xpath="Tick"/>
              <xs:field xpath="@count"/>
              </xs:unique>
              </xs:element>
              [/code]

              Comment

              • gnomff
                New Member
                • Mar 2008
                • 5

                #8
                Originally posted by jkmyoung
                [code=xml]
                <xs:element name="somthing" >
                <xs:complexType >
                <xs:sequence>
                <xs:element name="somthinge lse" type="xs:long"/>
                <xs:element name="Tick" type="TickType" maxOccurs="unbo unded" minOccurs="0"/>
                </xs:sequence>
                </xs:complexType>
                <xs:unique name="Tick">
                <xs:selector xpath="Tick"/>
                <xs:field xpath="@count"/>
                </xs:unique>
                </xs:element>
                [/code]
                It's still passing even when I use that code. I've tried several different validators now to see if maybe xsv didn't have unique implemented, but with no success.

                Comment

                • jkmyoung
                  Recognized Expert Top Contributor
                  • Mar 2006
                  • 2057

                  #9
                  Can you post your full xml? Perhaps there's something in the structure I'm missing.

                  Comment

                  Working...