473,769 Members | 8,134 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.x sd:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefa ult="qualified" attributeFormDe fault="unqualif ied">
<xs:element name="function_ list">
<xs:complexType >
<xs:sequence maxOccurs="unbo unded">
<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.x ml:

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

Jul 26 '06 #1
2 1893
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*********@gma il.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.x sd:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefa ult="qualified" attributeFormDe fault="unqualif ied">
<xs:element name="function_ list">
<xs:complexType >
<xs:sequence maxOccurs="unbo unded">
<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.x ml:

<?xml version="1.0" encoding="UTF-8"?>
<function_lis t xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespace SchemaLocation= "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*********@gma il.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.x sd:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefa ult="qualified" attributeFormDe fault="unqualif ied">
<xs:element name="function_ list">
<xs:complexType >
<xs:sequence maxOccurs="unbo unded">
<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.x ml:

<?xml version="1.0" encoding="UTF-8"?>
<function_lis t xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespace SchemaLocation= "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
1552
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 from 1 to 50. Each child element is optional (i.e. there don't have to be 50 altogether) but each ID (1-50) may occur only once within the parent element. The best definition I have so far is this: <xs:element name="allPeriodData">...
1
1420
by: Maxim | last post by:
If there is a document like this: <Configurations> <Configuration default="true"> ... </Configuration> <Configuration> ...
2
2216
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"> <list name="hello"> <item action='allow' order="1"/>
1
376
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 language since malformed XML documents break the updater. (I did not have time to add good error-handling code, so run-time errors can abound if the document is malformed.) A sample doc might look something like this: <manifest>
2
1685
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 products like this one: <!-- File: Products.xml --> ... <Product id="p1">
2
4033
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 wrong or give me other solution. Thanks Very much. Regards ------------------------------------------------------------------------------------------------------------------ Schema:
0
2559
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
9613
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> <subsection name="first"> <!-- subsection contents -->
0
2824
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? Here’s a working example: <xs:schema id="schema" targetNamespace="http://tempuri.org/schema.xsd" elementFormDefault="qualified" xmlns="http://tempuri.org/schema.xsd" xmlns:mstns="http://tempuri.org/schema.xsd" ...
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10219
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10049
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9998
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3967
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.