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

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: [xml-dev] Creating a XML Schema for an existing database

[ Lists Home | Date Index | Thread Index ]

It took FOREVER to find this problem. Note to XML Schema implementors: 
make debugging of this kind of thing easier! Unfortunately this was one 
of those problems that felt like it should be working an just wasn't so 
I sat and tried to solve it until I found the problem...

First, the obvious errors include poor prefixing. These really aren't 
obvious, but when you have done enough key/keyrefs its the first thing 
to look for. You had:

<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>

You need:

<xs:keyref name="RefEmployeeToDepartment" refer="KeyDepartmentByID">
   <xs:selector xpath="s:Employees/s:Employee"/>
   <xs:field xpath="s:Department/@refDepartmentID"/>
</xs:keyref>
<xs:key name="KeyDepartmentByID">
   <xs:selector xpath="s:Departments/s:Department"/>
   <xs:field xpath="@departmentID"/>
</xs:key>

Now, some processors will let you get away with poor prefixing. But 
don't do it. This brings me to the second point which is dual namespace 
declarations:

   xmlns="http://www.example.org/hr/stafflist";
   xmlns:s="http://www.example.org/hr/stafflist";

Now, this can just cause a maintenance nightmare. I recommend only using 
prefixed namespaces in XML Schemas-- the strange cases where items need 
to be prefixed and qualified can cause problems (as shown above).

Now to the real meat of the problem-- type specificity. The types of 
your keys and references did not match. Throughout the schema you had 
type="xs:integer" for all of your ids/refs *except* for:

   <xs:attribute name="departmentID"/>

In XSV and Xerces keys and keyrefs apparently treat simple ur-type and 
xs:string the same, but they do not type xs:integer and simple ur-type 
the same. MSXML would not allow you to mix xs:integer and a simple 
ur-type nor would it allow you to mix xs:string and a simple ur-type. So 
you need to change your deaprtmentID attribute declaration to:

   <xs:attribute name="departmentID" type="xs:integer"/>

Alternatively you can remove the type on the attribute declaration for 
refDepartmentID-- as all three allow you to compare simple ur-type to 
simple ur-type.

All the best,
Jeff Rafter




 

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

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