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

Using <choice> to enforce rules


xs attribute
Hi,

I try to use W3C schema to enforce a business rule so that only one of the
two attributes can have blank value.  

My schema structure is one attribute group with two attributes which
requires value, one attribute group with two attributes which only first
attribute requires value and one attribute group with same two attributes
which only second attribute requires value.  Then I have two groups (element
groups), first group have the first and second attribute groups and second
group have first and third attribute group.  Last I create the element which
uses a <choice> with reference to the two element groups.  The schema and an
instance document are below.

I created it in XML Spy 4 and it works as expected.  But when I use Java
with Xerces 1.4 deployed on Weblogic, it always validates against the first
item in the <choice>.  

Can anyone see any problems in my schema design?

Thanks a lot,

Sean

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
	<xs:attributeGroup name="AttGroupA">
		<xs:attribute name="AA">
			<xs:simpleType>
				<xs:restriction base="xs:string">
					<xs:minLength value="1"/>
				</xs:restriction>
			</xs:simpleType>		
		</xs:attribute>
		<xs:attribute name="BB">
			<xs:simpleType>
				<xs:restriction base="xs:string">
					<xs:minLength value="1"/>
				</xs:restriction>
			</xs:simpleType>			
		</xs:attribute>
	</xs:attributeGroup>
	<xs:attributeGroup name="AttGroupB">
		<xs:attribute name="CC">
			<xs:simpleType name="">
				<xs:restriction base="xs:string">
					<xs:maxLength value="40"/>
				</xs:restriction>
			</xs:simpleType>
		</xs:attribute>	
		<xs:attribute name="DD">
			<xs:simpleType name="">
				<xs:restriction base="xs:string">
					<xs:minLength value="1"/>
					<xs:maxLength value="40"/>
				</xs:restriction>
			</xs:simpleType>
		</xs:attribute>	
	</xs:attributeGroup>
	<xs:attributeGroup name="AttGroupC">
		<xs:attribute name="CC">
			<xs:simpleType name="">
				<xs:restriction base="xs:string">
					<xs:minLength value="1"/>
					<xs:maxLength value="40"/>
				</xs:restriction>
			</xs:simpleType>
		</xs:attribute>	
		<xs:attribute name="DD">
			<xs:simpleType name="">
				<xs:restriction base="xs:string">

					<xs:maxLength value="40"/>
				</xs:restriction>
			</xs:simpleType>
		</xs:attribute>	
	</xs:attributeGroup>
	<xs:group name="ElementGroupA">
		<xs:sequence>
			<xs:element name="ElementA">
				<xs:complexType name="">

					<xs:attributeGroup ref="AttGroupA"/>
					<xs:attributeGroup ref="AttGroupB"/>
				</xs:complexType>
			</xs:element>
		</xs:sequence>
	</xs:group>
	<xs:group name="ElementGroupB">
		<xs:sequence>
			<xs:element name="ElementA">
				<xs:complexType name="">

					<xs:attributeGroup ref="AttGroupA"/>
					<xs:attributeGroup ref="AttGroupC"/>
				</xs:complexType>
			</xs:element>
		</xs:sequence>
	</xs:group>
	<xs:element name="TEST">
		<xs:complexType>
			<xs:choice>
				<xs:group ref="ElementGroupA"/>
				<xs:group ref="ElementGroupB"/>
			</xs:choice>
		</xs:complexType>
	</xs:element>
</xs:schema>

<?xml version="1.0" encoding="UTF-8"?>
<TEST xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="D:\Test.xsd">
	<ElementA AA="A" BB="B" CC="" DD=""/>
</TEST>



PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

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-2013 All Rights Reserved.