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

XML Schema <xs:unique/> scope

Hi,

I've written a schema that looks like :

<xs:schema>
<xs:complexType name="myType">
<xs:sequence>
<xs:element name="e1" type="T1" maxOccurs="unbounded"/>
<xs:element name="e2" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="T1">
<xs:sequence>
<xs:element name="e3" type="T3" maxOccurs="unbounded"/>
<xs:element name="e4" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="T3">
<xs:sequence>
<xs:element name="name" type="xs:string" maxOccurs="unbounded"/>
<xs:element name="adress" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:element name="myElement" type="myType">
<xs:unique name="uniqueName>
<xs:selector xpath="./e1/e3"/>
<xs:field xpath="name"/>
</xs:unique>
</xs:element>
</xs:schema>

The <xs:unique/element garantees there is only one element "./e1/e3"
in my xml file that has a given name. This prevents me from having 2
elements with the same name in 2 different e1 elements because my
<xs:unique/element is in the scope of "myElement". I would like to
be allowed to name two element e3 with the same name providing they do
not have the same e1 ancestor. Therefore I have to define my
<xs:unique/element in the scope of "myElement/e1" instead of
"myElement".
How do I do that given that I want to keep defining all my complex
types before defining the "myElement" element ? I would like to avoid
defining more than one <xs:element/element.

Thanks,

Cédric

Feb 14 '07 #1
1 3999
Hi Cédric,

ce***********@gmail.com writes:
<xs:schema>
<xs:complexType name="myType">
<xs:sequence>
<xs:element name="e1" type="T1" maxOccurs="unbounded"/>
<xs:element name="e2" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="T1">
<xs:sequence>
<xs:element name="e3" type="T3" maxOccurs="unbounded"/>
<xs:element name="e4" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="T3">
<xs:sequence>
<xs:element name="name" type="xs:string" maxOccurs="unbounded"/>
<xs:element name="adress" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:element name="myElement" type="myType">
<xs:unique name="uniqueName>
<xs:selector xpath="./e1/e3"/>
<xs:field xpath="name"/>
</xs:unique>
</xs:element>
</xs:schema>

Therefore I have to define my <xs:unique/element in the scope
of "myElement/e1" instead of "myElement".

How do I do that given that I want to keep defining all my complex
types before defining the "myElement" element ? I would like to avoid
defining more than one <xs:element/element.
You would just add unique to the e1 element declaration:

<xs:complexType name="myType">
<xs:sequence>
<xs:element name="e1" type="T1" maxOccurs="unbounded">
<xs:unique name="uniqueName>
<xs:selector xpath="e3"/>
<xs:field xpath="name"/>
</xs:unique>
</xs:element>
<xs:element name="e2" type="xs:string"/>
</xs:sequence>
<xs:complexType>
hth,
-boris
--
Boris Kolpackov
Code Synthesis Tools CC
http://www.codesynthesis.com
Open-Source, Cross-Platform C++ XML Data Binding
Feb 14 '07 #2

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

Similar topics

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)...
1
by: Vijay | last post by:
<xs:element name="product"> <xs:complexType> <xs:complexContent> <xs:restriction base="xs:integer"> <xs:attribute name="prodid" type="xs:positiveInteger"/> </xs:restriction>...
2
by: nosferatu_1_1 | last post by:
Hi, I would like to create a schema that validate the following xml: <music> <pop/> <rock/> <pop/> </music>
0
by: Simon Neve | last post by:
Hi, I have several datasets that use exactly the same element. From reading MSDN it appears I can split the common element into its own dataset and use the <xs: include element from any dataset...
1
by: jlea | last post by:
Does anyone know if xsd.exe in .NET v2.0 supports <xs:list> in element types? Thanks. Jon.
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">...
0
by: mavis | last post by:
How to parse a XSD file and get info inside <xs:appinfo>? JDOM supports this? Thanks!!!
2
by: hooomee | last post by:
Given: <xs:choice maxOccurs=5> <xs:element name="Foo" type="bar" /> <xs:element name="Foo1" type="bar" /> <xs:element name="Foo2" type="bar" /> </xs:choice> Is the choice made once and then...
2
by: Aray | last post by:
I googled for it for few houres, but didn't resolve it, any hints will be thinkfull. I want to use the following XSD file to guarantee <element1is unique, but it doesn't work. The following...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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.