unique attribute value

P

pstachy

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>
 
M

Martin Honnen

pstachy said:
<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>
 
P

pstachy

Thanks, it works:)

Martin Honnen napisal(a):
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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,007
Messages
2,570,266
Members
46,863
Latest member
montyonthebonty

Latest Threads

Top