Verifying the contents with key, keyref

K

koch.henning

Hello,

I have some sort of problem with verifying the contents of my
xml-document.
I have a xml-scheme like this...

<xs:complexType name="abcType">
<xs:sequence>
<xs:element name="elementA" type="elementAType"/>
<xs:element name="elementB" type="elementBType"/>
<xs:element name="elementC" type="elementCType"/>
</xs:sequence>
<xs:attribute name="ID" type="xs:string"/>
</xs:complexType>

This abcType has an Attribute ID. And each of these elementA,B,C-Types
has
Subelements. Now I want to verify some things in the xml-document
with the key-, keyref-Elements.
I want to get only the some special sub-elements of elementBType.

I tried something like this:

<xs:element name="abc" type="abcType">

<xs:key name="IDKey">
<xs:selector xpath=".//elementB/specialSubElementB"/>
<xs:field xpath="@ID"/>
</xs:key>

This way I get the sub-elements of TypeB, but the Problem is, that the
ID is in TypeB not in its
sub-Elements.
The problem is, that I can't refer the parent-element to the ID
Normally you could write something like this:
xpath=".//elementB/[specialSubElementB]"/ so only the elements are
taken, who have the subElementB. But this doesn't seem to work. I tried
it in Avolta XML-Spy with the "Evaluate Path" and gave him the command
with the brackets (xpath=".//elementB/[specialSubElementB]"/) and the
correct elements were selected but in the selector-element this doesn't
seem to work.

I could move the ID-Attribute to each subElement-Type, but it would be
much better for my scheme if I would leave it at the parent-element
abcType.
Are the any work-arounds or does anybody know a solution for this
problem?

Any help would be appreciated,
thanks...
Henning.
 
S

Stan Kitsis [MSFT]

Hi Henning,

All xpath attributes should use namespace when referring to elements.

<xs:schema .... targetNamespace="myTargetNamespace"
xmlns:myNS="myTargetNamespace" xmlns="myTargetNamespace"...>

<xs:selector xpath=".//myNS:elementB/myNS:specialSubElementB"/>

--
Stan Kitsis
Program Manager, XML Technologies
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,905
Latest member
Kristy_Poole

Latest Threads

Top