unique attribute value

Discussion in 'XML' started by pstachy, Nov 5, 2006.

  1. pstachy

    pstachy Guest

    Hi again!
    I have another issue. I would like the attribute of the tag <invoice>
    to be unique. Made the following schema but unfortunately it doesn't
    validate. Could someone please indicate what is wrong or give me other
    solution. Thanks Very much.

    Regards

    ------------------------------------------------------------------------------------------------------------------
    Schema:

    <xs:element name="invoice">
    <xs:complexType>


    <xs:attribute name="number" type="xs:uniqueString" use="required"/>
    <!-- I want the attribute 'number' to be unique
    -->
    </xs:complexType>

    <xs:unique name="unique_fn_name">
    <xs:selector xpath="invoice"/>
    <xs:field xpath="@number"/>
    </xs:unique>
    </xs:element>

    ------------------------------------------------------------------------------------------------------
    XML:

    <invoices>
    <invoice number="asd" /> <!-- unfortunately not unique yet -->
    <invoice number="asd" />
    <invoice number="acd" />
    <invoice number="acd" />
    </invoices>
    pstachy, Nov 5, 2006
    #1
    1. Advertising

  2. pstachy wrote:

    > <xs:element name="invoice">
    > <xs:complexType>
    >
    >
    > <xs:attribute name="number" type="xs:uniqueString" use="required"/>
    > <!-- I want the attribute 'number' to be unique
    > -->
    > </xs:complexType>
    >
    > <xs:unique name="unique_fn_name">
    > <xs:selector xpath="invoice"/>
    > <xs:field xpath="@number"/>
    > </xs:unique>
    > </xs:element>
    >
    > ------------------------------------------------------------------------------------------------------
    > XML:
    >
    > <invoices>
    > <invoice number="asd" /> <!-- unfortunately not unique yet -->
    > <invoice number="asd" />
    > <invoice number="acd" />
    > <invoice number="acd" />
    > </invoices>


    If you want the number attribute value to be unique in the complete XML
    document then you could simply use
    <xs:attribute name="number" type="xs:ID" use="required"/>

    If you want the number attribute to be unique for each invoice child
    element of the invoices element then you need to put the xs:unique
    constraint as a child of the invoices definition e.g.

    <xs:element name="invoices">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="invoice" maxOccurs="unbounded">
    <xs:complexType>
    <xs:attribute name="number" type="xs:string" use="required"/>
    </xs:complexType>
    </xs:element>
    </xs:sequence>
    </xs:complexType>
    <xs:unique name="unique-number">
    <xs:selector xpath="invoice"/>
    <xs:field xpath="@number"/>
    </xs:unique>
    </xs:element>




    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Nov 5, 2006
    #2
    1. Advertising

  3. pstachy

    pstachy Guest

    Thanks, it works:)

    Martin Honnen napisal(a):
    > pstachy wrote:
    >
    > > <xs:element name="invoice">
    > > <xs:complexType>
    > >
    > >
    > > <xs:attribute name="number" type="xs:uniqueString" use="required"/>
    > > <!-- I want the attribute 'number' to be unique
    > > -->
    > > </xs:complexType>
    > >
    > > <xs:unique name="unique_fn_name">
    > > <xs:selector xpath="invoice"/>
    > > <xs:field xpath="@number"/>
    > > </xs:unique>
    > > </xs:element>
    > >
    > > ------------------------------------------------------------------------------------------------------
    > > XML:
    > >
    > > <invoices>
    > > <invoice number="asd" /> <!-- unfortunately not unique yet -->
    > > <invoice number="asd" />
    > > <invoice number="acd" />
    > > <invoice number="acd" />
    > > </invoices>

    >
    > If you want the number attribute value to be unique in the complete XML
    > document then you could simply use
    > <xs:attribute name="number" type="xs:ID" use="required"/>
    >
    > If you want the number attribute to be unique for each invoice child
    > element of the invoices element then you need to put the xs:unique
    > constraint as a child of the invoices definition e.g.
    >
    > <xs:element name="invoices">
    > <xs:complexType>
    > <xs:sequence>
    > <xs:element name="invoice" maxOccurs="unbounded">
    > <xs:complexType>
    > <xs:attribute name="number" type="xs:string" use="required"/>
    > </xs:complexType>
    > </xs:element>
    > </xs:sequence>
    > </xs:complexType>
    > <xs:unique name="unique-number">
    > <xs:selector xpath="invoice"/>
    > <xs:field xpath="@number"/>
    > </xs:unique>
    > </xs:element>
    >
    >
    >
    >
    > --
    >
    > Martin Honnen
    > http://JavaScript.FAQTs.com/
    pstachy, Nov 5, 2006
    #3
    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:
    518
    James J. Foster
    Aug 7, 2003
  2. Replies:
    1
    Views:
    4,236
    Joe Kesselman
    Aug 2, 2006
  3. Replies:
    8
    Views:
    512
  4. ToshiBoy
    Replies:
    6
    Views:
    829
    ToshiBoy
    Aug 12, 2008
  5. kanpeter

    unique attribute value

    kanpeter, Oct 11, 2010, in forum: XML
    Replies:
    1
    Views:
    1,072
    Martin Honnen
    Oct 11, 2010
Loading...

Share This Page