Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   XML (http://www.velocityreviews.com/forums/f32-xml.html)
-   -   unique attribute value (http://www.velocityreviews.com/forums/t392445-unique-attribute-value.html)

pstachy 11-05-2006 05:04 PM

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>


Martin Honnen 11-05-2006 05:23 PM

Re: unique attribute value
 
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 11-05-2006 06:16 PM

Re: unique attribute value
 
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/




All times are GMT. The time now is 10:24 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.