- From: Henry S. Thompson <ht@cogsci.ed.ac.uk>
- Date: Thu, 25 Sep 2003 14:51:23 +0100
- To: "Andrew H McDowall" <ahm@cs.stir.ac.uk>
- Cc: xmlschema-dev@w3.org
"Andrew H McDowall" <ahm@cs.stir.ac.uk> writes: > I am fairly new the XML Schema and I am trying to define a schema that > offers a choice between elements with the same name but with different > attributes. For example: > > <if index="xs:integer" last="yes|no"/> > > or > > <if name="xs:string"/> > > or > > <if type="xs:string" not="xs:string"/> > > Is this possible with XSD or do I need to embed some schematron? Further > more would it be possible to define an abstract tpye <if/> and use the > above choice as a substitution group? Exactly as you've written it, W3C XML Schema can't help. There are two possible workarounds: Give your <if> element an abstract type, which allows all your possible attributes as optional, and sub-type it with variants which make some fixed and others required or forbidden, then use xsi:type in the instance to select the relevant case: <if xsi:type="my:int" index="xs:integer" last="yes|no"/> <if xsi:type="my:str1" name="xs:string"/> <if xsi:type="my:str2" type="xs:string" not="xs:string"/> Alternatively, move the variation into the element names -- make <if> itself abstract as well, define <if_int> with type my:int, <if_str1> with type my:str1, etc, and have them all identity <if> as their substitution group head. Then you can have <if_int index="xs:integer" last="yes|no"/> <if_str1 name="xs:string"/> <if_str2 type="xs:string" not="xs:string"/> in your instance where <if> is expected. Hope this helps. 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@cogsci.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]
Received on Thursday, 25 September 2003 09:51:25 UTC