OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Using <choice> to enforce rules

[ Lists Home | Date Index | Thread Index ]

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>






 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS