Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XML Schema <xs:unique/> scope

Reply
Thread Tools

XML Schema <xs:unique/> scope

 
 
cedric.louyot@gmail.com
Guest
Posts: n/a
 
      02-14-2007
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

 
Reply With Quote
 
 
 
 
Boris Kolpackov
Guest
Posts: n/a
 
      02-14-2007
Hi CÚdric,

http://www.velocityreviews.com/forums/(E-Mail Removed) 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
 
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
web.xml / XML schema issue, why do some XML schema attributes disappear asciz@starmail.com Java 3 02-20-2007 09:56 AM
Validation with XSD using XML::LibXML::Schema, and XML::Validator::Schema huntingseasonson@gmail.com Perl Misc 5 11-29-2006 12:37 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 to XML Schema Conversion Hari Om XML 1 03-02-2004 09:04 PM
XML schema regular expressions question and recommended XML Schema book Fred Smith XML 1 02-05-2004 11:12 AM



Advertisments