Verifying the contents with key, keyref

Discussion in 'XML' started by koch.henning@googlemail.com, Jun 15, 2006.

  1. Guest

    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.
     
    , Jun 15, 2006
    #1
    1. Advertising

  2. 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

    <> wrote in message
    news:...
    > 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.
    >
     
    Stan Kitsis [MSFT], Jun 16, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marek Malowidzki

    Key/keyref validation in schema?

    Marek Malowidzki, Aug 18, 2003, in forum: XML
    Replies:
    1
    Views:
    513
    Mark Preston
    Aug 19, 2003
  2. J E E
    Replies:
    0
    Views:
    381
    J E E
    Nov 7, 2003
  3. peterpeter
    Replies:
    0
    Views:
    931
    peterpeter
    Feb 11, 2004
  4. Markus Seibold

    <key><keyref> does not work in XMLSpy

    Markus Seibold, Feb 13, 2004, in forum: XML
    Replies:
    0
    Views:
    1,314
    Markus Seibold
    Feb 13, 2004
  5. Russell O'Connor

    Key-keyref to attribute in root element

    Russell O'Connor, Mar 5, 2004, in forum: XML
    Replies:
    5
    Views:
    990
    Henry S. Thompson
    Apr 27, 2004
Loading...

Share This Page