[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Key and Keyref not working properly

  • To: <xml-dev@l...>
  • Subject: Key and Keyref not working properly
  • From: "Marco Mastrocinque" <mmfive@n...>
  • Date: Sun, 27 Mar 2005 19:24:17 +1000
  • Cc: "Jeff Rafter" <lists@j...>,"Henry S. Thompson" <ht@i...>
  • Thread-index: AcUyrr/V91EbajObQiWX9xOtkvBbBA==

xs unique not working
Hi All,
       I'm using key and keyref system to implement Primary and Foreign Key
relationships. I have tried everything; I'm using Apache Xerecs to validate
it. If I can implement the 'refDID' attribute in Employee to reference the
'DID' attribute in Division, I can do the rest myself. Any suggestions most
appreciated. Please have a look at the files inserted with my email. It will
not catch the deliberate errors I have introduced.  

Thanks Marco Mastrocinque
   
    
<?xml version="1.0" encoding="UTF-8"?>
<companyInformationSystem xmlns="http://www.myexample/companyInformationSystem" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.myexample/companyInformationSystem
company.xsd">
	<Divisions>
		<Division DID="Mar">
			<DName>Marketing</DName>
			<Location>10th Floor - D Block</Location>
		</Division>
		<Division DID="Wmd">
			<DName>Research and Development</DName>
			<Location>12th Floor - A Block</Location>
		</Division>
	</Divisions>
	<Employess>
		<Employee EID="S12345" refDID="Marr">
			<ENAME>Marco Mastrocinque</ENAME>
			<OFFICE>1204</OFFICE>
			<BIRTHDATE>07061970</BIRTHDATE>
			<SALARY>650000</SALARY>
		</Employee>
		<Employee EID="XXXXXX" refDID="xxx">
			<ENAME>John Smith</ENAME>
			<OFFICE>12th Floor - A Block</OFFICE>
			<BIRTHDATE>07011969</BIRTHDATE>
			<SALARY>50000</SALARY>
		</Employee>
	</Employess>
	<Projects>
		<Project PID="M34" refDID="Mar">
			<PNAME>Just Jeans commercial</PNAME>
			<BUDGET>650000</BUDGET>
		</Project>
	</Projects>
	<Assigns>
		<Assign refDID="Mar" refEID="S12345">
			<HOURS>0012</HOURS>
		</Assign>
	</Assigns>
</companyInformationSystem>
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.myexample/companyInformationSystem" xmlns:c="http://www.myexample/companyInformationSystem" targetNamespace="http://www.myexample/companyInformationSystem" elementFormDefault="qualified">
	<!--The root element companyIformationSystem -->
	<xs:element name="companyInformationSystem">
		<xs:annotation>
			<xs:documentation>This is the root element of the XML file. Assignment done by Marco Mastrocinque (s8812209), Bill Kascamanidis (s5391490) and Alex Filip (s4035542).</xs:documentation>
		</xs:annotation>
		<xs:complexType>
			<xs:sequence>
				<!--The first major subgroup Divisions -->
				<xs:element name="Divisions">
					<xs:complexType>
						<xs:sequence>
							<!--The subgroup Division -->
							<xs:element ref="Division" maxOccurs="unbounded"/>
						</xs:sequence>
					</xs:complexType>
					<!--Declare DID as unique -->
					<!--This part part works -->
					<xs:unique name="divisionIDNumber">
						<xs:selector xpath="c:Division"/>
						<xs:field xpath="@DID"/>
					</xs:unique>
				</xs:element>
				<!--The second major subgroup Employess-->
				<xs:element name="Employess">
					<xs:complexType>
						<xs:sequence>
							<!--The subgroup Employee-->
							<xs:element ref="Employee" maxOccurs="unbounded"/>
						</xs:sequence>
					</xs:complexType>
					<!--Declare the combination of EID and refDID is unique -->
					<!--This part works -->
					<xs:unique name="employeeEIDandrefDID">
						<xs:selector xpath="c:Employee"/>
						<xs:field xpath="@EID"/>
					</xs:unique>
					<!--This is where you reference the DID attribute (Foreign  Key) in the Division subgroup  -->
					<xs:keyref name="RefEmployeeToDivision" refer="KeyEmployeeByDivisionID">
						<xs:selector xpath="c:Employees/c:Employee"/>
						<xs:field xpath="@refDID"/>
					</xs:keyref>
					<!-- The Primary Key the DID attribute in the Employee subgroup -->
					<xs:key name="KeyEmployeeByDivisionID">
						<xs:selector xpath="c:Divisions/c:Division"/>
						<xs:field xpath="@DID"/>
					</xs:key>
				</xs:element>
				<!--The third major subgroup Projects -->
				<xs:element name="Projects">
					<xs:complexType>
						<xs:sequence>
							<!--The subgroup Project -->
							<xs:element ref="Project" maxOccurs="unbounded"/>
						</xs:sequence>
					</xs:complexType>
				</xs:element>
				<!--This is the fouth and major subgroup Assigns -->
				<xs:element name="Assigns">
					<xs:complexType>
						<xs:sequence>
							<xs:element ref="Assign" maxOccurs="unbounded"/>
						</xs:sequence>
					</xs:complexType>
				</xs:element>
			</xs:sequence>
		</xs:complexType>
	</xs:element>
	<!--This is the Division subgroup -->
	<xs:element name="Division">
		<xs:complexType>
			<xs:sequence>
				<xs:element name="DName" type="xs:string"/>
				<xs:element name="Location" type="xs:string"/>
			</xs:sequence>
			<xs:attribute name="DID" type="xs:string" use="required"/>
		</xs:complexType>
	</xs:element>
	<!--This is the Employee subgroup -->
	<xs:element name="Employee">
		<xs:complexType>
			<xs:sequence>
				<xs:element name="ENAME" type="xs:string"/>
				<xs:element name="OFFICE" type="xs:string"/>
				<xs:element name="BIRTHDATE" type="xs:string"/>
				<xs:element name="SALARY" type="xs:integer"/>
			</xs:sequence>
			<xs:attribute name="EID" type="xs:string" use="required"/>
			<xs:attribute name="refDID" type="xs:string" use="required"/>
		</xs:complexType>
	</xs:element>
	<!--This is the Project subgroup -->
	<xs:element name="Project">
		<xs:complexType>
			<xs:sequence>
				<xs:element name="PNAME" type="xs:string"/>
				<xs:element name="BUDGET" type="xs:integer"/>
			</xs:sequence>
			<xs:attribute name="PID" type="xs:string" use="required"/>
			<xs:attribute name="refDID" type="xs:string" use="required"/>
		</xs:complexType>
	</xs:element>
	<!--This is the Assign subgroup -->
	<xs:element name="Assign">
		<xs:complexType>
			<xs:sequence>
				<xs:element name="HOURS" type="xs:integer"/>
			</xs:sequence>
			<xs:attribute name="refDID" type="xs:string" use="required"/>
			<xs:attribute name="refEID" type="xs:string" use="required"/>
		</xs:complexType>
	</xs:element>
</xs:schema>

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.