469,958 Members | 1,976 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,958 developers. It's quick & easy.

unique attribute value

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>

Nov 5 '06 #1
2 3854
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/
Nov 5 '06 #2
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/
Nov 5 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Peter N. Schweitzer | last post: by
1 post views Thread by Ulf Heyder | last post: by
reply views Thread by johkar | last post: by
2 posts views Thread by Gadrin77 | last post: by
2 posts views Thread by Miguel Isidoro | last post: by
1 post views Thread by daldridge | last post: by
reply views Thread by rainxy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.