You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Mark Lines-Davies <ml...@spd.sonybpe.com> on 2002/02/01 09:45:31 UTC

RE: Xerces 1.4.1 problem with Java

Hi Sean

I had a similar problem with Xerces 2 beta.

As far as I can see, Xerces only matches elements not attributes. So if the
two options in an <xsd:choice> are identical as far as element names are
concerned, and only differ with regard to attributes, Xerces chooses the
first option every time.

Essentially I was trying to distinguish between <A><B/><C/><D/></A> and
<A><C/></A> by having a choice between two groups. Group 2 had minOccurs="0"
for B and D, but <A><C/></A> would always be validated against group 1 and
fail.

I tried to read the W3C documents to see if this was the correct behaviour,
but it was too much like hard work, so I just changed the XML design.

regards

Mark Lines-Davies
Sony BPE, Basingstoke, UK

-----Original Message-----
From: Sean Zhang [mailto:Sean.Zhang@ins.gte.com]
Sent: 31 January 2002 21:20
To: xerces-j-user@xml.apache.org
Subject: Xerces 1.4.1 problem with Java


Hi,

I'm using Xerces 1.4.1 in my Java code deployed on Weblogic6.1 to validate
XML with reference to W3C schema.

The purpose is to validate the XML so that if Zipcode is left blank, City
and State have to be filled out or if City and State are left blank, Zipcode
has to be filled out.
I verified the XML in XML spy 4 against the schema and the rules are working
there.

When I run my code on Weblogic, it seems to me what rule to use depends on
the sequence of the xsd:group I specify.  (see the bold part in the schema.
If I specify eltGRPAddrZipCodeOptional first then I have to enter value for
City attribute even if I fill out Zipcode correctly otherwise I receive a
parsing error.  If I specify eltGRPAddrZipCodeMandatory first, I have to
fill out Zipcode even if I filled out both City and State otherwise, I
receive a parsing error.

Just wondering if this is the designed behavior of Xerces 1.4.1.  If is the
by design, any later version added the feature so that the xml can be
validated correctly?

Thanks,

Sean


The XML I have is similar to following

<?xml version="1.0"?>
<Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://localhost:7001/schema/MySchema.xsd">
	<Data>
		<Address Street="123 main street" City="" State="IL"
Zipcode="60090"/>
	</Data>
</Root>

The schema is similar to following

<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
	<xsd:attributeGroup name="attrGRPAddrBasic">
		<xsd:attribute name="Street" use="required">
			<xsd:simpleType>
				<xsd:restriction base="xsd:string">
					<xsd:minLength value="1"/>
					<xsd:maxLength value="64"/>
				</xsd:restriction>
			</xsd:simpleType>
		</xsd:attribute>
	</xsd:attributeGroup>
	<xsd:attributeGroup name="attrGRPZipCodeOptional">
		<xsd:attribute name="City" use="required">
			<xsd:simpleType>
				<xsd:restriction base="xsd:string">
					<xsd:minLength value="1"/>
					<xsd:maxLength value="40"/>
				</xsd:restriction>
			</xsd:simpleType>
		</xsd:attribute>
		<xsd:attribute name="State" use="required">
			<xsd:simpleType>
				<xsd:restriction base="xsd:string">
					<xsd:pattern value="[A-Z]{2}"/>
				</xsd:restriction>
			</xsd:simpleType>
		</xsd:attribute>
		<xsd:attribute name="Zipcode" use="required">
			<xsd:simpleType>
				<xsd:restriction base="xsd:string">
					<xsd:pattern value="([0-9]{5})?"/>
				</xsd:restriction>
			</xsd:simpleType>
		</xsd:attribute>
	</xsd:attributeGroup>
	<xsd:attributeGroup name="attrGRPZipCodeMandatory">
		<xsd:attribute name="City" use="required">
			<xsd:simpleType>
				<xsd:restriction base="xsd:string">
					<xsd:maxLength value="40"/>
				</xsd:restriction>
			</xsd:simpleType>
		</xsd:attribute>
		<xsd:attribute name="State" use="required">
			<xsd:simpleType>
				<xsd:restriction base="xsd:string">
					<xsd:pattern value="([A-Z]{2})?"/>
				</xsd:restriction>
			</xsd:simpleType>
		</xsd:attribute>
		<xsd:attribute name="Zipcode" use="required">
			<xsd:simpleType>
				<xsd:restriction base="xsd:string">
					<xsd:pattern value="[0-9]{5}"/>
				</xsd:restriction>
			</xsd:simpleType>
		</xsd:attribute>
	</xsd:attributeGroup>
	<xsd:group name="eltGRPAddrZipCodeOptional">
		<xsd:all>
			<xsd:element name="Address">
				<xsd:complexType>
					<xsd:attributeGroup
ref="attrGRPAddrBasic"/>
					<xsd:attributeGroup
ref="attrGRPZipCodeOptional"/>
				</xsd:complexType>
			</xsd:element>
		</xsd:all>
	</xsd:group>
	<xsd:group name="eltGRPAddrZipCodeMandatory">
		<xsd:all>
			<xsd:element name="Address">
				<xsd:complexType>
					<xsd:attributeGroup
ref="attrGRPAddrBasic"/>
					<xsd:attributeGroup
ref="attrGRPZipCodeMandatory"/>
				</xsd:complexType>
			</xsd:element>
		</xsd:all>
	</xsd:group>
	<xsd:element name="Data">
		<xsd:complexType>
			<xsd:sequence>
				<xsd:choice>
					<xsd:group
ref="eltGRPAddrZipCodeOptional"/>
					<xsd:group
ref="eltGRPAddrZipCodeMandatory"/>

				</xsd:choice>
			</xsd:sequence>
		</xsd:complexType>
	</xsd:element>
	<xsd:element name="Root">
		<xsd:complexType>
			<xsd:sequence>
				<xsd:element ref="Data"/>
			</xsd:sequence>
		</xsd:complexType>
	</xsd:element>
</xsd:schema>



---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org




*************************************************************************
The information contained in this message or any of its
attachments may be privileged and confidential and intended 
for the exclusive use of the addressee. If you are not the
addressee any disclosure, reproduction, distribution or other
dissemination or use of this communication is strictly prohibited
*************************************************************************

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org