Fwd: Re: Choice: attribute or child element [retry]

[I didn't see this show up in the archives so will try again]

>Date: Fri, 06 Dec 2002 22:07:31 -0500
>To: xmlschema-dev@w3.org
>From: "G. Ken Holman" <gkholman@CraneSoftwrights.com>
>Subject: Re: Choice: attribute or child element
>
>At 2002-12-06 15:15 -0800, Alessandro Vernet wrote:
>>Is there a way to write a schema to validate documents that look like: 
>><a><b/></a>, or <a c="..."/> (i.e. the element "a" must have a child 
>>element "b" or an attribute "c", but not both)?
>
>T:\ftemp>type allesandro.rnc
>element a
>{
>    (
>       element b { text } |
>       attribute c { text }
>    )
>}
>T:\ftemp>type allesandro1.xml
><?xml version="1.0" encoding="iso-8859-1"?>
><a><b/></a>
>T:\ftemp>jing -c allesandro.rnc allesandro1.xml
>
>T:\ftemp>type allesandro2.xml
><?xml version="1.0" encoding="iso-8859-1"?>
><a c=""></a>
>T:\ftemp>jing -c allesandro.rnc allesandro2.xml
>
>T:\ftemp>type allesandro3.xml
><?xml version="1.0" encoding="iso-8859-1"?>
><a c=""><b/></a>
>T:\ftemp>jing -c allesandro.rnc allesandro3.xml
>Error at URL "file:/T:/ftemp/allesandro3.xml", line number 2: element "b" 
>not allowed in this context
>
>T:\ftemp>
>
>OOooops ... sorry, wrong list to give this answer!  Then again, you just 
>said "write a schema" not "write a W3C schema".
>
>Joking aside, I don't think this can be done in W3C Schema (if it can, I'd 
>like to see how!) ... it can be done in RELAX-NG because RELAX-NG is fully 
>composable: there is no prejudice to elements or attributes in "content 
>models", they can be combined in co-occurrence constraints any way you need.
>
>I hope this helps.
>
>.............. Ken


--
Upcoming hands-on in-depth XSLT/XPath and/or XSL-FO:
-                             North America:  Feb 3 - Feb 7,2003

G. Ken Holman               mailto:gkholman@CraneSoftwrights.com
Crane Softwrights Ltd.        http://www.CraneSoftwrights.com/x/
Box 266, Kars, Ontario CANADA K0A-2E0  +1(613)489-0999 (F:-0995)
ISBN 0-13-065196-6                     Definitive XSLT and XPath
ISBN 0-13-140374-5                             Definitive XSL-FO
ISBN 1-894049-08-X Practical Transformation Using XSLT and XPath
ISBN 1-894049-10-1             Practical Formatting Using XSL-FO
Next conference training:                    2002-12-08,03-03,06

Received on Sunday, 8 December 2002 21:56:16 UTC