M
Markus Seibold
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 <AdminUnitName> element which should be the key. I then
declared the <keyref> in the context of the <SubAdminUnits> element and
specified the XPath to the <SubAdminUnitName> 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
<SubAdminUnitName>.
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="http://www.opentourism.org"
xmlns:gml="http://www.opengis.net/gml" elementFormDefault="unqualified">
<!-- ========================== -->
<!-- include/import of other schemas -->
<!-- ========================== -->
<include schemaLocation="TourML_DataTypes_1-0.xsd"/>
<!-- ======================== -->
<!-- ===== Country element ===== -->
<!-- ======================== -->
<element name="Country" type="utour:CountryType">
<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="SuperAdminUnit_SubAdminUnit_Key">
<selector xpath="CountryAdminUnits/AdminUnit"/>
<field xpath="AdminUnitName"/>
</key>
</element>
<!-- ====================================== -->
<!-- ===== Country - AdminUnit Relationship ===== -->
<!-- ====================================== -->
<complexType name="_CountryAdminUnit">
<annotation>
<documentation>Administrative Units that belong to a certain
country. _CountryAdminUnit is the correspondent to the 1:n relationship
between Country and AdminUnit in TourDM.</documentation>
</annotation>
<sequence>
<element name="AdminUnit" type="utour:AdminUnitType"/>
</sequence>
</complexType>
<!-- ===================== -->
<!-- ===== CountryType===== -->
<!-- ===================== -->
<complexType name="CountryType">
<sequence>
<element name="CountryID" type="utour:CountryIDType"/>
<element name="CountryName" type="utour:MaxCharacter30Type"/>
<element name="CountryPhoneCode" type="integer"/>
<element name="CountryGratuityGuideline"
type="utour:MaxCharacter100Type" minOccurs="0"/>
<element name="CountryBestTravelTime"
type="utour:MaxCharacter100Type" minOccurs="0"/>
<element name="CountryAdminUnits" type="utour:_CountryAdminUnit"
minOccurs="0" maxOccurs="unbounded"/>
</sequence>
</complexType>
<!-- ======================= -->
<!-- ===== AdminUnitType ===== -->
<!-- ======================= -->
<complexType name="AdminUnitType">
<sequence>
<element name="AdminUnitName" type="utour:MaxCharacter128Type"/>
<element name="SubAdminUnits" type="utour:_SubAdminUnit"
minOccurs="0" maxOccurs="unbounded">
<keyref name="SuperAdminUnit_SubAdminUnit_Ref"
refer="utour:SuperAdminUnit_SubAdminUnit_Key">
<selector xpath="."/>
<field xpath="SubAdminUnitName"/>
</keyref>
</element>
<element name="AdminUnitType">
<simpleType>
<restriction base="string">
<enumeration value="State" xml:lang="en-US"/>
<enumeration value="County" xml:lang="en-US"/>
<enumeration value="Bundesland" xml:lang="de"/>
<enumeration value="Regierungsbezirk" xml:lang="de"/>
<enumeration value="Landkreis" xml:lang="de"/>
</restriction>
</simpleType>
</element>
</sequence>
</complexType>
<!-- ====================================== -->
<!--===== AdminUnit Recursive Relationship ===== -->
<!-- ====================================== -->
<complexType name="_SubAdminUnit">
<annotation>
<documentation>_SubAdminUnit is the correspondent to the 1:n
recursive relationship between AdminUnit and AdminUnit in
TourDM.</documentation>
</annotation>
<sequence>
<element name="SubAdminUnitName" type="utour:MaxCharacter128Type"/>
</sequence>
</complexType>
</schema>
<?xml version="1.0" encoding="UTF-8"?>
<utour:Country xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:utour="http://www.opentourism.org"
xsi:schemaLocation="http://www.opentourism.org
D:\Eigene~1\Studium\diplom~1\TourML\TourML_1-0\___TourML_Geography_1-0.xsd">
<CountryID>US</CountryID>
<CountryName>United States of America</CountryName>
<CountryPhoneCode>1</CountryPhoneCode>
<CountryAdminUnits>
<AdminUnit>
<AdminUnitName>Georgia</AdminUnitName>
<SubAdminUnits>
<SubAdminUnitName>XXXClarke County</SubAdminUnitName>
</SubAdminUnits>
<SubAdminUnits>
<SubAdminUnitName>Oconee County</SubAdminUnitName>
</SubAdminUnits>
<AdminUnitType>State</AdminUnitType>
</AdminUnit>
</CountryAdminUnits>
<CountryAdminUnits>
<AdminUnit>
<AdminUnitName>Clarke County</AdminUnitName>
<SubAdminUnits>
<SubAdminUnitName></SubAdminUnitName>
</SubAdminUnits>
<AdminUnitType>County</AdminUnitType>
</AdminUnit>
</CountryAdminUnits>
<CountryAdminUnits>
<AdminUnit>
<AdminUnitName>Oconee County</AdminUnitName>
<SubAdminUnits>
<SubAdminUnitName></SubAdminUnitName>
</SubAdminUnits>
<AdminUnitType>County</AdminUnitType>
</AdminUnit>
</CountryAdminUnits>
</utour:Country>
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 <AdminUnitName> element which should be the key. I then
declared the <keyref> in the context of the <SubAdminUnits> element and
specified the XPath to the <SubAdminUnitName> 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
<SubAdminUnitName>.
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="http://www.opentourism.org"
xmlns:gml="http://www.opengis.net/gml" elementFormDefault="unqualified">
<!-- ========================== -->
<!-- include/import of other schemas -->
<!-- ========================== -->
<include schemaLocation="TourML_DataTypes_1-0.xsd"/>
<!-- ======================== -->
<!-- ===== Country element ===== -->
<!-- ======================== -->
<element name="Country" type="utour:CountryType">
<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="SuperAdminUnit_SubAdminUnit_Key">
<selector xpath="CountryAdminUnits/AdminUnit"/>
<field xpath="AdminUnitName"/>
</key>
</element>
<!-- ====================================== -->
<!-- ===== Country - AdminUnit Relationship ===== -->
<!-- ====================================== -->
<complexType name="_CountryAdminUnit">
<annotation>
<documentation>Administrative Units that belong to a certain
country. _CountryAdminUnit is the correspondent to the 1:n relationship
between Country and AdminUnit in TourDM.</documentation>
</annotation>
<sequence>
<element name="AdminUnit" type="utour:AdminUnitType"/>
</sequence>
</complexType>
<!-- ===================== -->
<!-- ===== CountryType===== -->
<!-- ===================== -->
<complexType name="CountryType">
<sequence>
<element name="CountryID" type="utour:CountryIDType"/>
<element name="CountryName" type="utour:MaxCharacter30Type"/>
<element name="CountryPhoneCode" type="integer"/>
<element name="CountryGratuityGuideline"
type="utour:MaxCharacter100Type" minOccurs="0"/>
<element name="CountryBestTravelTime"
type="utour:MaxCharacter100Type" minOccurs="0"/>
<element name="CountryAdminUnits" type="utour:_CountryAdminUnit"
minOccurs="0" maxOccurs="unbounded"/>
</sequence>
</complexType>
<!-- ======================= -->
<!-- ===== AdminUnitType ===== -->
<!-- ======================= -->
<complexType name="AdminUnitType">
<sequence>
<element name="AdminUnitName" type="utour:MaxCharacter128Type"/>
<element name="SubAdminUnits" type="utour:_SubAdminUnit"
minOccurs="0" maxOccurs="unbounded">
<keyref name="SuperAdminUnit_SubAdminUnit_Ref"
refer="utour:SuperAdminUnit_SubAdminUnit_Key">
<selector xpath="."/>
<field xpath="SubAdminUnitName"/>
</keyref>
</element>
<element name="AdminUnitType">
<simpleType>
<restriction base="string">
<enumeration value="State" xml:lang="en-US"/>
<enumeration value="County" xml:lang="en-US"/>
<enumeration value="Bundesland" xml:lang="de"/>
<enumeration value="Regierungsbezirk" xml:lang="de"/>
<enumeration value="Landkreis" xml:lang="de"/>
</restriction>
</simpleType>
</element>
</sequence>
</complexType>
<!-- ====================================== -->
<!--===== AdminUnit Recursive Relationship ===== -->
<!-- ====================================== -->
<complexType name="_SubAdminUnit">
<annotation>
<documentation>_SubAdminUnit is the correspondent to the 1:n
recursive relationship between AdminUnit and AdminUnit in
TourDM.</documentation>
</annotation>
<sequence>
<element name="SubAdminUnitName" type="utour:MaxCharacter128Type"/>
</sequence>
</complexType>
</schema>
<?xml version="1.0" encoding="UTF-8"?>
<utour:Country xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:utour="http://www.opentourism.org"
xsi:schemaLocation="http://www.opentourism.org
D:\Eigene~1\Studium\diplom~1\TourML\TourML_1-0\___TourML_Geography_1-0.xsd">
<CountryID>US</CountryID>
<CountryName>United States of America</CountryName>
<CountryPhoneCode>1</CountryPhoneCode>
<CountryAdminUnits>
<AdminUnit>
<AdminUnitName>Georgia</AdminUnitName>
<SubAdminUnits>
<SubAdminUnitName>XXXClarke County</SubAdminUnitName>
</SubAdminUnits>
<SubAdminUnits>
<SubAdminUnitName>Oconee County</SubAdminUnitName>
</SubAdminUnits>
<AdminUnitType>State</AdminUnitType>
</AdminUnit>
</CountryAdminUnits>
<CountryAdminUnits>
<AdminUnit>
<AdminUnitName>Clarke County</AdminUnitName>
<SubAdminUnits>
<SubAdminUnitName></SubAdminUnitName>
</SubAdminUnits>
<AdminUnitType>County</AdminUnitType>
</AdminUnit>
</CountryAdminUnits>
<CountryAdminUnits>
<AdminUnit>
<AdminUnitName>Oconee County</AdminUnitName>
<SubAdminUnits>
<SubAdminUnitName></SubAdminUnitName>
</SubAdminUnits>
<AdminUnitType>County</AdminUnitType>
</AdminUnit>
</CountryAdminUnits>
</utour:Country>