CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2012
    Posts
    2

    Question How to use key, key ref in XSD

    Hi all:
    I am trying to use keys and keyrefs in XSD without any success (I am a newbie in XSD). For example, this XSD does not work as the attached XML object demonstrates:
    <?xml version="1.0" encoding="UTF-8"?>
    <schema xmlns="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://www.example.org/sc"
    xmlns:fh="http://www.example.org/sc" elementFormDefault="qualified">
    <element name="Orders">
    <complexType>
    <sequence minOccurs="1" maxOccurs="unbounded">
    <element name="AnOrder">
    <complexType>
    <attribute name="orderId" type="string" use="required" />
    </complexType>
    </element>
    </sequence>
    </complexType>
    <unique name="orderKey">
    <selector xpath="Orders/Order" />
    <field xpath="@orderId" />
    </unique>
    </element>
    </schema>

    I thought that with this definitions any order must have a unique orderId attribute.
    The prof that this does not work is this XML object (I am validating the objects with the Eclipse support tools):

    <?xml version="1.0" encoding="UTF-8"?>
    <fh:Orders xmlns:fh="http://www.example.org/sc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.example.org/sc sc.xsd ">
    <fh:AnOrder orderId="1" />
    <fh:AnOrder orderId="1" />
    </fh:Orders>
    Coul anybody with some skills in XSD help me with this?

  2. #2
    Join Date
    Feb 2012
    Posts
    2

    Re: How to use key, key ref in XSD

    I found a solution using elements instead of attributes:
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://www.fhgg.org"
    xmlns="http://www.fhgg.org"
    xmlns:fh="http://www.fhgg.org"
    elementFormDefault="qualified">
    <xs:element name="Root">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="Orders">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="AnOrder" minOccurs="0" maxOccurs="unbounded">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="orderId" type="xs:string" />
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:sequence>
    </xs:complexType>
    <xs:key name="orderKey">
    <xs:selector xpath="fh:Orders/fh:AnOrder" />
    <xs:field xpath="fhrderId" />
    </xs:key>
    </xs:element>
    </xs:schema>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured