Hello NG,
sorry for pasting that much code but I just can't figure out how get the
<key><keyref> to work in XML Schema. I am using XMLSpy 4.3 for editing my
XML. I want to represent a recursive 1:n relationship between a database
table AdminUnit (i.e., States consist of Counties).
I declared the <key> element in the context of <country> and specified the
XPath to the <AdminUnitNam e> element which should be the key. I then
declared the <keyref> in the context of the <SubAdminUnit s> element and
specified the XPath to the <SubAdminUnitNa me> element which should be the
foreign key pointing to the primary key.
I also pasted a XML instance document at the end of this message. The
document validates in XMLSpy although I specified a non-existend
<SubAdminUnitNa me>.
I just can't figure out why this doesn't work. Could it be that the code
actually is correct but XMLSpy cannot handle the <key><keyref> elements?
I'd really appreciate any help!!!
Thanks, Markus
<?xml version="1.0" encoding="UTF-8"?>
<schema targetNamespace ="http://www.opentourism .org"
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:utour="ht tp://www.opentourism .org"
xmlns:gml="http ://www.opengis.net/gml" elementFormDefa ult="unqualifie d">
<!-- =============== =========== -->
<!-- include/import of other schemas -->
<!-- =============== =========== -->
<include schemaLocation= "TourML_DataTyp es_1-0.xsd"/>
<!-- =============== ========= -->
<!-- ===== Country element ===== -->
<!-- =============== ========= -->
<element name="Country" type="utour:Cou ntryType">
<annotation>
<documentation> Country is declared as sub-element of the schema
element; it can function as a root element in an instance
document.</documentation>
</annotation>
<key name="SuperAdmi nUnit_SubAdminU nit_Key">
<selector xpath="CountryA dminUnits/AdminUnit"/>
<field xpath="AdminUni tName"/>
</key>
</element>
<!-- =============== =============== ======== -->
<!-- ===== Country - AdminUnit Relationship ===== -->
<!-- =============== =============== ======== -->
<complexType name="_CountryA dminUnit">
<annotation>
<documentation> Administrative Units that belong to a certain
country. _CountryAdminUn it is the correspondent to the 1:n relationship
between Country and AdminUnit in TourDM.</documentation>
</annotation>
<sequence>
<element name="AdminUnit " type="utour:Adm inUnitType"/>
</sequence>
</complexType>
<!-- =============== ====== -->
<!-- ===== CountryType==== = -->
<!-- =============== ====== -->
<complexType name="CountryTy pe">
<sequence>
<element name="CountryID " type="utour:Cou ntryIDType"/>
<element name="CountryNa me" type="utour:Max Character30Type "/>
<element name="CountryPh oneCode" type="integer"/>
<element name="CountryGr atuityGuideline "
type="utour:Max Character100Typ e" minOccurs="0"/>
<element name="CountryBe stTravelTime"
type="utour:Max Character100Typ e" minOccurs="0"/>
<element name="CountryAd minUnits" type="utour:_Co untryAdminUnit"
minOccurs="0" maxOccurs="unbo unded"/>
</sequence>
</complexType>
<!-- =============== ======== -->
<!-- ===== AdminUnitType ===== -->
<!-- =============== ======== -->
<complexType name="AdminUnit Type">
<sequence>
<element name="AdminUnit Name" type="utour:Max Character128Typ e"/>
<element name="SubAdminU nits" type="utour:_Su bAdminUnit"
minOccurs="0" maxOccurs="unbo unded">
<keyref name="SuperAdmi nUnit_SubAdminU nit_Ref"
refer="utour:Su perAdminUnit_Su bAdminUnit_Key" >
<selector xpath="."/>
<field xpath="SubAdmin UnitName"/>
</keyref>
</element>
<element name="AdminUnit Type">
<simpleType>
<restriction base="string">
<enumeration value="State" xml:lang="en-US"/>
<enumeration value="County" xml:lang="en-US"/>
<enumeration value="Bundesla nd" xml:lang="de"/>
<enumeration value="Regierun gsbezirk" xml:lang="de"/>
<enumeration value="Landkrei s" xml:lang="de"/>
</restriction>
</simpleType>
</element>
</sequence>
</complexType>
<!-- =============== =============== ======== -->
<!--===== AdminUnit Recursive Relationship ===== -->
<!-- =============== =============== ======== -->
<complexType name="_SubAdmin Unit">
<annotation>
<documentation> _SubAdminUnit is the correspondent to the 1:n
recursive relationship between AdminUnit and AdminUnit in
TourDM.</documentation>
</annotation>
<sequence>
<element name="SubAdminU nitName" type="utour:Max Character128Typ e"/>
</sequence>
</complexType>
</schema>
<?xml version="1.0" encoding="UTF-8"?>
<utour:Countr y xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
xmlns:utour="ht tp://www.opentourism .org"
xsi:schemaLocat ion="http://www.opentourism .org
D:\Eigene~1\Stu dium\diplom~1\T ourML\TourML_1-0\___TourML_Geo graphy_1-0.xsd">
<CountryID>US </CountryID>
<CountryName>Un ited States of America</CountryName>
<CountryPhoneCo de>1</CountryPhoneCod e>
<CountryAdminUn its>
<AdminUnit>
<AdminUnitName> Georgia</AdminUnitName>
<SubAdminUnit s>
<SubAdminUnitNa me>XXXClarke County</SubAdminUnitNam e>
</SubAdminUnits>
<SubAdminUnit s>
<SubAdminUnitNa me>Oconee County</SubAdminUnitNam e>
</SubAdminUnits>
<AdminUnitType> State</AdminUnitType>
</AdminUnit>
</CountryAdminUni ts>
<CountryAdminUn its>
<AdminUnit>
<AdminUnitName> Clarke County</AdminUnitName>
<SubAdminUnit s>
<SubAdminUnitNa me></SubAdminUnitNam e>
</SubAdminUnits>
<AdminUnitType> County</AdminUnitType>
</AdminUnit>
</CountryAdminUni ts>
<CountryAdminUn its>
<AdminUnit>
<AdminUnitName> Oconee County</AdminUnitName>
<SubAdminUnit s>
<SubAdminUnitNa me></SubAdminUnitNam e>
</SubAdminUnits>
<AdminUnitType> County</AdminUnitType>
</AdminUnit>
</CountryAdminUni ts>
</utour:Country>