[XMLSCHEMA-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: How to choice the attribute group for element?

From: Michael Kay <mike@saxonica.com>
Date: Tue, 9 Jun 2009 09:38:17 +0100
To: "'bacoo'" <bacoo_zh@163.com>, "'xmlschema-dev'" <xmlschema-dev@w3.org>
Message-ID: <521050DBC54049A3A137D20AEF24B704@Sealion>
RE: How to choice the attribute group for element?
> This is my first time to have a discussion here. I'm new to 
> XML Schema.
> Now I want to define an element with three attributes: A, B 
> and C. However, I don't want the three attributes occur 
> simultaneously.
> I need A and B occur simultaneously, or only C occurs singlely.

I'm afraid it's a well-known limitation of XSD 1.0 that you can't do this.
It always surprises newcomers, but I'm afraid it's true. The limitation
disappears in XSD 1.1, but that's still "on the drawing board" and not yet
supported in most products.

If you want to try it out, Saxon-SA 9.1 does support the new feature of
"conditional type assignment". However, the "mainstream" solution to this
kind of requirement is to supplement XSD validation with another validation
pass using Schematron, which allows testing your document against arbitrary
predicates.

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay 


> 
> <x A="a" B="b"/>
> or
> <x C="c">
>  	 EG320270420CN
> How to do this?
> I use 'choic' to implement this as follows, but it don't work.
> <xs:choice maxOccurs="unbounded">
>       <xs:element name="x"  type="xs:string"> 
> <xs:complexType> <xs:attribute name="A" type="xs:string"/> 
> <xs:attribute name="B" type="xs:string"/> </xs:complexType>
>       </xs:element>
>       <xs:element name="x"  type="xs:string"> 
> <xs:complexType> <xs:attribute name="C" type="xs:string"/> 
> </xs:complexType>
>       </xs:element>
> </xs:choice>
> By the way, after goooooogling, I found that the code above 
> is right in the old XML Schema criteria, but nowadays I can't 
> use it any more and the XMLSpy software will report errors 
> with the code above. Is there anyone that know about the 
> related information?
> It has bothered me several days. I'll appreciate your help sincerely.
> 
> 
> 
> 
Received on Tuesday, 9 June 2009 08:38:56 GMT

Subscribe to the Stylus Scoop newsletter for helpful XML tips and tutorials.
Email
First Name
Last Name
Company

Download Stylus Studio 6 XML Enterprise Edition

Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.