473,320 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 4001
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Peter N. Schweitzer | last post by:
The function get_meta_tags reads a file or URL and returns an array, one element for each META tag in the HEAD element of the document. The keys of this array are the values of the name attribute...
1
by: Ulf Heyder | last post by:
Hello everyone, I want to add a unique constraint to a XSD I created. After I modified validation (XMLSpy, Castor-0.9.5 marshaller) of my example (see below) against the XSD (also see below)...
0
by: johkar | last post by:
In the below example I am using the following to try to match only the unique MechanismText nodes within each Subscription node: select="DeliveryPreferences/DeliveryPreference" Right now, the...
2
by: Gadrin77 | last post by:
is it possible to get a unique ID or key for a union of the following XML <Bonus> <BonusItem Name="Category One" Value="1"/> <BonusItem Name="Category One" Value="1"/> <BonusItem Name="Category...
0
by: James J. Foster | last post by:
Is there a way to instruct visual studio to give each instance of a user control a unique attribute value, by specifying a pattern for an incremental index? Similar to how visual studio...
2
by: sachinik19 | last post by:
Hi, xml file : ------------- <?xml version='1.0'?> <query xmlns='jabber:iq:privacy' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="jabber:iq:privacy privacy.xsd">...
2
by: Miguel Isidoro | last post by:
Hi all, I am trying to include a xsd:unique element in my schema to make an attribute of an element unique at the whole document level. Consider the following xml fragment: <Form>...
1
by: daldridge | last post by:
I have a unique-elements/sorting question (who doesn't?), but haven't yet been able to get appropriate template/select/for-each processing working. I don't fully grok the Muenchian technique yet...
1
by: Asko Telinen | last post by:
Hi all. I´m a bit newbie writing xml schemas. Is it possible to define xml element that must have unique attribute values in same level. For example if i have a xml - document: <list>...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.