Groups | Blog | Home
all groups > dotnet xml > march 2005 >

dotnet xml : uniqueness schema problem


Mr. Almenares
3/4/2005 1:47:10 PM
Hello:

I’m trying to do a schema with recurrent structure for a Book like a Node
can have many Nodes inside or One leave. So, the leaves have an attribute
that is Identifier. My goal is define Uniqueness that guarantees to the
attribute Identifier his uniqueness. That I don’t know the depth of levels I
have to put in the xpath attribute of the selector something like this
TOC/descendant::Tree/Data, but this is not allow. How I can resolve.
This is the simplified version of the schema.

Hello:

I’m trying to do a schema with recurrent structure for a Book like a Node
can have many Nodes inside or One leave. So, the leaves have an attribute
that is Identifier. My goal is define Uniqueness that guarantees to the
attribute Identifier his uniqueness. That I don’t know the depth of levels I
have to put in the xpath attribute of the selector something like this
TOC/descendant::Tree/Data, but this is not allow. How I can resolve.
This is the simplified version of the schema.

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="Book">
<xs:complexType>
<xs:sequence>
<xs:element name="TOC">
<xs:complexType>
<xs:sequence>
<xs:element name="Tree" type="typeTree" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>

<xs:key name="UTree">
<xs:selector xpath="TOC/descendant::Tree/Data"/> HERE IS THE PROBLEM
<xs:field xpath="@Identifier"/>
</xs:key>
</xs:element>

<xs:complexType name="typeTree">
<xs:choice>
<xs:element name="Tree" type="typeTree" maxOccurs="unbounded"/>
<xs:element name="Data" nillable="true">
<xs:complexType>
<xs:attribute name="Identifier" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:schema>

Priscilla Walmsley
3/6/2005 6:24:12 PM
Hi,

If you put your key in the TOC element declaration instead, you can start
the path with ".//", which I think would meet your needs. So it would look
like this:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="Book">
<xs:complexType>
<xs:sequence>
<xs:element name="TOC">
<xs:complexType>
<xs:sequence>
<xs:element name="Tree" type="typeTree" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:key name="UTree">
<xs:selector xpath=".//Tree/Data"/> HERE IS THE SOLUTION
<xs:field xpath="@Identifier"/>
</xs:key>
</xs:element>
</xs:sequence>
</xs:complexType>

</xs:element>
....

Hope that helps,
Priscilla
------------------------------------------------------------------
Priscilla Walmsley
Author, Definitive XML Schema / XML in Office 2003
http://www.datypic.com
------------------------------------------------------------------

[quoted text, click to view]

AddThis Social Bookmark Button