Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > simple problem trying to specify a unique attribute with XML schema

Reply
Thread Tools

simple problem trying to specify a unique attribute with XML schema

 
 
smachin1000@gmail.com
Guest
Posts: n/a
 
      07-26-2006
Hi All,

In the sample schema & document below, I'd like the attribute "name" to
be unique for all function elements under function_list. The tools I'm
using (XML Spy and xmllint) all validate the sample document and do not
pick up that the name is not unique.
Any clues as to what could be going wrong?

Thanks.

-----------------------------------------------------------------------------------------------------------------------------
function_list.xsd:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlnss="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="function_list">
<xs:complexType>
<xs:sequence maxOccurs="unbounded">
<xs:element ref="function"/>
</xs:sequence>
</xs:complexType>
<xs:unique name="unique_fn_name">
<xs:selector xpath="function_list"/>
<xs:field xpath="@name"/>
</xs:unique>
</xs:element>
<xs:element name="function">
<xs:complexType>
<xs:attribute name="name" type="xs:string" use="required"/>
<!-- want the above attribute to be unique -->
</xs:complexType>
</xs:element>
</xs:schema>

-----------------------------------------------------------------------------------------------------------------------------
function_list.xml:

<?xml version="1.0" encoding="UTF-8"?>
<function_list xmlnssi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="function_list.xsd">
<function name="fred"/>
<function name="fred"/>
<function name="frog"/>
<function name="fred"/>
</function_list>

 
Reply With Quote
 
 
 
 
George Bina
Guest
Posts: n/a
 
      07-27-2006
Hi,

Your unique constrint does not select any nodes because you are in a
function_list element and you select as selector all the cildren
elements that have the name function_list and there are no such
elements in your instance document

<xs:selector xpath="function_list"/>

What you want is probably

<xs:selector xpath="function"/>

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

wrote:
> Hi All,
>
> In the sample schema & document below, I'd like the attribute "name" to
> be unique for all function elements under function_list. The tools I'm
> using (XML Spy and xmllint) all validate the sample document and do not
> pick up that the name is not unique.
> Any clues as to what could be going wrong?
>
> Thanks.
>
> -----------------------------------------------------------------------------------------------------------------------------
> function_list.xsd:
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema xmlnss="http://www.w3.org/2001/XMLSchema"
> elementFormDefault="qualified" attributeFormDefault="unqualified">
> <xs:element name="function_list">
> <xs:complexType>
> <xs:sequence maxOccurs="unbounded">
> <xs:element ref="function"/>
> </xs:sequence>
> </xs:complexType>
> <xs:unique name="unique_fn_name">
> <xs:selector xpath="function_list"/>
> <xs:field xpath="@name"/>
> </xs:unique>
> </xs:element>
> <xs:element name="function">
> <xs:complexType>
> <xs:attribute name="name" type="xs:string" use="required"/>
> <!-- want the above attribute to be unique -->
> </xs:complexType>
> </xs:element>
> </xs:schema>
>
> -----------------------------------------------------------------------------------------------------------------------------
> function_list.xml:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <function_list xmlnssi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:noNamespaceSchemaLocation="function_list.xsd">
> <function name="fred"/>
> <function name="fred"/>
> <function name="frog"/>
> <function name="fred"/>
> </function_list>


 
Reply With Quote
 
 
 
 
smachin1000@gmail.com
Guest
Posts: n/a
 
      07-27-2006
Thanks George,

Your advice worked
The other thing that was tripping me up is that my real world example
(as opposed to the canonical example I posted here) was using a default
namespace, so I had to some further tweaking to get the xpath expr. to
work correctly.


George Bina wrote:
> Hi,
>
> Your unique constrint does not select any nodes because you are in a
> function_list element and you select as selector all the cildren
> elements that have the name function_list and there are no such
> elements in your instance document
>
> <xs:selector xpath="function_list"/>
>
> What you want is probably
>
> <xs:selector xpath="function"/>
>
> Best Regards,
> George
> ---------------------------------------------------------------------
> George Cristian Bina
> <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
> http://www.oxygenxml.com
>
> wrote:
> > Hi All,
> >
> > In the sample schema & document below, I'd like the attribute "name" to
> > be unique for all function elements under function_list. The tools I'm
> > using (XML Spy and xmllint) all validate the sample document and do not
> > pick up that the name is not unique.
> > Any clues as to what could be going wrong?
> >
> > Thanks.
> >
> > -----------------------------------------------------------------------------------------------------------------------------
> > function_list.xsd:
> > <?xml version="1.0" encoding="UTF-8"?>
> > <xs:schema xmlnss="http://www.w3.org/2001/XMLSchema"
> > elementFormDefault="qualified" attributeFormDefault="unqualified">
> > <xs:element name="function_list">
> > <xs:complexType>
> > <xs:sequence maxOccurs="unbounded">
> > <xs:element ref="function"/>
> > </xs:sequence>
> > </xs:complexType>
> > <xs:unique name="unique_fn_name">
> > <xs:selector xpath="function_list"/>
> > <xs:field xpath="@name"/>
> > </xs:unique>
> > </xs:element>
> > <xs:element name="function">
> > <xs:complexType>
> > <xs:attribute name="name" type="xs:string" use="required"/>
> > <!-- want the above attribute to be unique -->
> > </xs:complexType>
> > </xs:element>
> > </xs:schema>
> >
> > -----------------------------------------------------------------------------------------------------------------------------
> > function_list.xml:
> >
> > <?xml version="1.0" encoding="UTF-8"?>
> > <function_list xmlnssi="http://www.w3.org/2001/XMLSchema-instance"
> > xsi:noNamespaceSchemaLocation="function_list.xsd">
> > <function name="fred"/>
> > <function name="fred"/>
> > <function name="frog"/>
> > <function name="fred"/>
> > </function_list>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
xml schema to specify element type based on attribute value? James XML 2 07-28-2007 04:11 AM
web.xml / XML schema issue, why do some XML schema attributes disappear asciz@starmail.com Java 3 02-20-2007 09:56 AM
Xml schema element with attribute and optional simple content? Gazza XML 1 12-05-2005 05:32 PM
[XML Schema] Including a schema document with absent target namespace to a schema with specified target namespace Stanimir Stamenkov XML 3 04-25-2005 09:59 AM
XML schema regular expressions question and recommended XML Schema book Fred Smith XML 1 02-05-2004 11:12 AM



Advertisments