473,371 Members | 1,499 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,371 software developers and data experts.

simple problem trying to specify a unique attribute with XML schema

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 xmlns:xs="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 xmlns:xsi="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>

Jul 26 '06 #1
2 1853
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

sm*********@gmail.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 xmlns:xs="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 xmlns:xsi="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>
Jul 27 '06 #2
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

sm*********@gmail.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 xmlns:xs="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 xmlns:xsi="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>
Jul 27 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Andy Howden | last post by:
I'm trying to define a schema element (allPeriodData) containing up to 50 different decimal child elements (periodData). Each child element (periodData) identifies itself with an ID having a value...
1
by: Maxim | last post by:
If there is a document like this: <Configurations> <Configuration default="true"> ... </Configuration> <Configuration> ...
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">...
1
by: Chris Lieb | last post by:
I am new to XML Schema and am running into a bit of a snag. I have defined an XML-based scripting language for an updater program that I am working on. I would like to make a schema for this...
2
by: Yarik | last post by:
Hello, I am not sure the subject of my post adequately describes the problem I am trying to solve, so I think a specific example would be helpful. Let's say there are XML descriptions of...
2
by: pstachy | last post by:
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...
0
by: Torsten Munkelt | last post by:
Hi, I want to write an XML-schema saying that this document <root> <edge type="special"> <target type="one"/> </edge> <edge type="special"> <target type="one"/>
1
by: Asko Telinen | last post by:
Hi all. Im 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: icesign | last post by:
I know that the selector of these elements has a scope relative to the element being declared, but maybe there is a way to get beyond bounds of this scope or maybe just a way to extend base element?...
1
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.