- From: Henry S. Thompson <ht@cogsci.ed.ac.uk>
- Date: 22 Aug 2001 13:27:03 +0100
- To: "Stephane Pageau" <spageau@sed.ara.com>
- Cc: <xmlschema-dev@w3.org>, <jpowell@sed.ara.com>
"Stephane Pageau" <spageau@sed.ara.com> writes: > 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 > > <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? Sure -- make the content of <vertexptr> be of type IDREF. As the REC notes, this is not backward compatible with DTDs -- if you changed to <vertexptr ref="30"/> that would no longer be a problem. Oops -- you can't use integers as IDs in XML. So make vertex ids be keys, and the content/ref of vertexptr be keyrefs. See [1] in the REC or [2] in the Primer. ht [1] http://www.w3.org/TR/xmlschema-1/#cIdentity-constraint_Definitions [2] http://www.w3.org/TR/xmlschema-0/#specifyingUniqueness -- Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh W3C Fellow 1999--2001, part-time member of W3C Team 2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440 Fax: (44) 131 650-4587, e-mail: ht@cogsci.ed.ac.uk URL: http://www.ltg.ed.ac.uk/~ht/
Received on Wednesday, 22 August 2001 08:26:41 UTC