W3C home > Mailing lists > Public > xmlschema-dev@w3.org > July 2001

Re: XML schema limitation?

From: Eric van der Vlist <vdv@dyomedea.com>
Date: Tue, 17 Jul 2001 16:27:18 +0200
Message-ID: <3B544B46.2BED7BC4@dyomedea.com>
To: Stephane Pageau <spageau@sed.ara.com>
Cc: xmlschema-dev@w3.org
Stephane Pageau wrote:
> 
> How can I construct a XML schema in which
> I wish to enforce that the content
> of an element (e.g., a subelement)
> be an existing element of the instance
> XML file?
> To clarify this question let me take an example:
> ------------------------------------------------
> Assume that I have a shape described using a
> bunch of vertices and I describe both the
> vertices and the shape separately as follows:
> <vertex id=10 >

You probably mean id="10" (otherwise it's not well formed XML) :=) ...

>    <x> 10. </x>
>    <y> 60. </y>
> </vertex>
> <vertex id=20 >
>    <x> 10. </x>
>    <y> 45. </y>
> </vertex>
> <vertex id=30 >
>    <x> 10. </x>
>    <y> 50. </y>
> </vertex>
> ...
> <shape id=1>
>    <vertexptr> 10 </vertexptr>
>    <vertexptr> 30 </vertexptr>
>    <vertexptr> 20 </vertexptr>
> </shape>
> How can I construct my schema to make sure that someone does not
> put <vertexptr> 1000 </vertexptr> if
> the vertex with id=1000 does not exist?
> 
> Note that I do not want to use the XML ref because there
> might be several shapes refering to the same vertex
> and I do not wish to repeat the coordinates of this vertex
> multiple times. That is, I do not want to do the following:
> <complexType name="vertex"/>
>   <all>
>    <element name="x" type="decimal" minOccurs="1"/>
>    <element name="y" type="decimal" minOccurs="1"/>
>   </all>
>   <attribute name="id" type="ID"/>

Type "ID" wouldn't do the deal anyway since it's derived from "NCName"
and cannot start with a number.

> </complexType>
> <complexType name="shape"/>
>    <element ref="vertex" minOccurs="1" maxOccurs="unbounded"/>
>    <attribute name="id" type="ID"/>

This could|should be type="IDREF" here, but again would not allow
numbers.

> </complexType>

What you need if I understand what you mean is a xs:key/xs:keyref, such
as:

<xs:element name="my-root">
	<xs:complexType>
	.../...
	</xs:complexType>
	<xs:key name="vertex">
		<xs:selector xpath="vertex"/>
		<xs:field xpath="@id"/>
	</xs:key>
	<xs:keyref name="vertexptr" refer="vertex">
		<xs:selector xpath="shape/vertexptr"/>
		<xs:field xpath="."/>
	</xs:keyref>
</xs:element>
 
Hope this helps.

Eric

> Stephane Pageau
> 811 Spring Forest Rd, Suite 100
> Raleigh, NC 27609
> mailto:spageau@sed.ara.com
> (919)876-0018
> fax: (919) 878-3672

-- 
See you at XTech in San Diego.
             http://conferences.oreillynet.com/cs/os2001/view/e_spkr/790
------------------------------------------------------------------------
Eric van der Vlist       http://xmlfr.org            http://dyomedea.com
http://xsltunit.org      http://4xt.org           http://examplotron.org
------------------------------------------------------------------------
Received on Tuesday, 17 July 2001 10:27:25 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:14:22 GMT