OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Creating a XML Schema for an existing database

[ Lists Home | Date Index | Thread Index ]
  • To: <xml-dev@lists.xml.org>
  • Subject: Creating a XML Schema for an existing database
  • From: "Marco Mastrocinque" <mmfive@netspace.net.au>
  • Date: Mon, 21 Mar 2005 20:05:01 +1100
  • Thread-index: AcUt9RADMuu7pzrpSpiY5aIL2WzJug==

Hi All,
       Currently studying XML Technologies at postgraduate level. I know
that you can use XML to replicate a database structure. I want to enforce
Data Integrity i.e. Entity integrity, Domain integrity, Referential
integrity and User-defined integrity. Can referential integrity be
maintained using Unique Values by the 'Key and Key References,' technique?

Please note I'm using the Apache Xerces validate tool. It does not seem to
catch a deliberate error I placed in it. Please excuse me for my ignorance
I'm still on my 'Learner Plates.'

Please see attached files.

Thanks Marco Mastrocinque
                
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"; xmlns="http://www.example.org/hr/stafflist"; xmlns:s="http://www.example.org/hr/stafflist"; targetNamespace="http://www.example.org/hr/stafflist"; elementFormDefault="qualified">
	<xs:element name="StaffList">
		<xs:complexType>
			<xs:sequence>
				<xs:element name="Employees" minOccurs="1" maxOccurs="1">
					<xs:complexType>
						<xs:sequence>
							<xs:element ref="Employee" minOccurs="1" maxOccurs="unbounded"/>
						</xs:sequence>
					</xs:complexType>
					<xs:unique name="employeeIdentifcationNumber">
						<xs:selector xpath="s:Employee"/>
						<xs:field xpath="@employeeID"/>
					</xs:unique>
				</xs:element>
				<xs:element name="Departments" minOccurs="1" maxOccurs="1">
					<xs:complexType>
						<xs:sequence>
							<xs:element ref="Department" maxOccurs="unbounded"/>
						</xs:sequence>
					</xs:complexType>
				</xs:element>
			</xs:sequence>
		</xs:complexType>
		<xs:keyref name="RefEmployeeToDepartment" refer="KeyDepartmentByID">
			<xs:selector xpath="Employees/s:Employee"/>
			<xs:field xpath="Department/@refDepartmentID"/>
		</xs:keyref>
		<xs:key name="KeyDepartmentByID">
			<xs:selector xpath="Departments/s:Department"/>
			<xs:field xpath="@departmentID"/>
		</xs:key>
	</xs:element>
	<xs:element name="Employee">
		<xs:complexType>
			<xs:sequence>
				<xs:element name="Name" type="NameType"/>
				<xs:element name="Department">
					<xs:complexType>
						<xs:attribute name="refDepartmentID" type="xs:integer"/>
					</xs:complexType>
				</xs:element>
				<xs:element name="JobTitle" type="xs:string"/>
			</xs:sequence>
			<xs:attribute name="employeeID" type="xs:integer"/>
		</xs:complexType>
	</xs:element>
	<xs:element name="Department">
		<xs:complexType>
			<xs:sequence>
				<xs:element name="DepartmentTitle" type="xs:string"/>
				<xs:element name="DepartmentManager">
					<xs:complexType>
						<xs:attribute name="refEmployeeID" type="xs:integer"/>
					</xs:complexType>
				</xs:element>
			</xs:sequence>
			<xs:attribute name="departmentID"/>
		</xs:complexType>
	</xs:element>
	<xs:complexType name="NameType">
		<xs:sequence>
			<xs:element name="FirstName" type="xs:string"/>
			<xs:element name="LastName" type="xs:string"/>
		</xs:sequence>
	</xs:complexType>
</xs:schema>
<?xml version="1.0" encoding="UTF-8"?>
<StaffList xmlns="http://www.example.org/hr/stafflist"; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xsi:schemaLocation="http://www.example.org/hr/stafflist
Example2.xsd">
	<Employees>
		<Employee employeeID="14">
			<Name>
				<FirstName>Amy</FirstName>
				<LastName>Robertson</LastName>
			</Name>
			<Department refDepartmentID="12"/>
			<JobTitle>Telesales Manager</JobTitle>
		</Employee>
	</Employees>
	<Departments>
		<Department departmentID="15">
			<DepartmentTitle>Telesales</DepartmentTitle>
			<DepartmentManager refEmployeeID="15"/>
		</Department>
	</Departments>
</StaffList>




 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS