XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
Re: [xml-dev] schema key/keyRef question - matching multiple keys

I wanted to follow up with a full solution to the subID/license plate problem (albeit a more redundant solution than I was hoping for - oh well).

Below is sample xml and an xsd. The xsd has a number of uniques and key/keyRef pairs that should prevent incorrect sub id matchings.

Seems like people on this list are certainly aware of this solution - but, figured I'd just finish off the thread.

zip here containing both files...

http://www.visual-io.com/dougXsdSample/xsdSubIDsExample.zip

cheers,

doug

XML...

<subIDsForProjects xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xsi:noNamespaceSchemaLocation="subIDs.xsd">
<meta>
<var name="String" vID="1">
<buckets>
<bucket bID="1" name="High" vID="1"/>
<bucket bID="2" name="Medium" vID="1"/>
<bucket bID="3" name="Low" vID="1"/>
</buckets>
</var>
<var name="String" vID="2">
<buckets>
<bucket bID="1" name="Top" vID="2"/>
<bucket bID="13" name="Bottom" vID="2"/>
</buckets>
</var>
</meta>
<projects>
<project name="Project 1">
<vars>
<var vID="1" bID="2"/>
<var vID="2" bID="1"/>
</vars>
</project>
<project name="Project 2">
<vars>
<var vID="1" bID="1"/>
<var vID="2" bID="13"/>
</vars>
</project>
</projects>
</subIDsForProjects>



XSD...

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"; elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="subIDsForProjects">
<xs:annotation>
<xs:documentation>Simple example showing key/keyRefs for creating "chained" key refs - doug marttila, doug@visual-io.com</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="meta">
<xs:complexType>
<xs:sequence>
<xs:element name="var" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="buckets">
<xs:complexType>
<xs:sequence>
<xs:element name="bucket" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="name" type="xs:string" use="required"/>
<xs:attribute name="vID" type="xs:nonNegativeInteger" use="required"/>
<xs:attribute name="bID" type="xs:nonNegativeInteger" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:unique name="bIDMetaUnique">
<xs:selector xpath="./bucket"/>
<xs:field xpath="@bID"/>
</xs:unique>
</xs:element>
</xs:sequence>
<xs:attribute name="vID" type="xs:nonNegativeInteger" use="required"/>
<xs:attribute name="name" type="xs:string" use="required"/>
</xs:complexType>
<xs:key name="IDKey">
<xs:selector xpath="."/>
<xs:field xpath="@vID"/>
</xs:key>
<xs:keyref name="IDKeyRef" refer="IDKey">
<xs:selector xpath="./buckets/bucket"/>
<xs:field xpath="@vID"/>
</xs:keyref>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:unique name="uniqueID">
<xs:selector xpath="./var"/>
<xs:field xpath="@vID"/>
</xs:unique>
</xs:element>
<xs:element name="projects">
<xs:complexType>
<xs:sequence>
<xs:element name="project" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="vars">
<xs:complexType>
<xs:sequence>
<xs:element name="var" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="vID" type="xs:nonNegativeInteger" use="required"/>
<xs:attribute name="bID" type="xs:nonNegativeInteger" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:unique name="varIDUniqueProject">
<xs:selector xpath="./var"/>
<xs:field xpath="@vID"/>
</xs:unique>
</xs:element>
</xs:sequence>
<xs:attribute name="name" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:key name="IDPairKey">
<xs:selector xpath="./meta/var/buckets/bucket"/>
<xs:field xpath="@bID"/>
<xs:field xpath="@vID"/>
</xs:key>
<xs:keyref name="IDPairKeyRef" refer="IDPairKey">
<xs:selector xpath="./projects/project/vars/var"/>
<xs:field xpath="@bID"/>
<xs:field xpath="@vID"/>
</xs:keyref>
<xs:key name="IDMetaProjectKey">
<xs:selector xpath="./meta/var"/>
<xs:field xpath="@vID"/>
</xs:key>
<xs:keyref name="IDMetaProjectKeyRef" refer="IDMetaProjectKey">
<xs:selector xpath="./projects/project/vars/var"/>
<xs:field xpath="@vID"/>
</xs:keyref>
</xs:element>
</xs:schema>




Henry S. Thompson wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Doug Marttila writes:

I am using a node in my xml to define variables. The defined variables
are referenced by ID in another node (a project). The problem is that
some variables have sub-ids (the variables are "buckets" instead of
numeric values, they can have values like "high" "med" "low")

This is, I'm sorry to say, a Frequently Requested Feature, i.e. there is no simple way to achieve what you want.

I think of this as the licence-plate problem -- cars have licence
plates, which specify state and plate number.  Within states, plate
numbers are unique.  Presuming a set of States keyed by @code, each
containing a sequence of IssuedPlates keyed by @number, to check an
ObservedPlate with @state and @number we need a _chained_ KeyRef,
i.e. use @state to identify a State, then use @number to identify an
IssuedPlate _within that State_.

The work-around you suggest (as it were, copying @code down from State
onto all IssuedPlates) is the only one I'm aware of.

ht
- -- Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
Half-time member of W3C Team
2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
Fax: (44) 131 650-4587, e-mail: ht@inf.ed.ac.uk
URL: http://www.ltg.ed.ac.uk/~ht/
[mail really from me _always_ has this .sig -- mail without it is forged spam]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)


iD8DBQFDvPIlkjnJixAXWBoRAtwnAJ9tlo6T26W5xXh0aHEHbgWRUmhiBwCeNrrq
58tk9hQGA87lf6jcQOlXG+0=
=RcnZ
-----END PGP SIGNATURE-----

-----------------------------------------------------------------
The xml-dev list is sponsored by XML.org <http://www.xml.org>, an
initiative of OASIS <http://www.oasis-open.org>

The list archives are at http://lists.xml.org/archives/xml-dev/

To subscribe or unsubscribe from this list use the subscription
manager: <http://www.oasis-open.org/mlmanage/index.php>






[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]





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

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