You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by "Smith, Doug" <Do...@fmr.com> on 2000/08/24 19:23:40 UTC

Bug report: schema attribute value enforcement

Greetings,

I'm seeing the following in the xml-xerces_20000822161937.tar.gz source
distribution:

When I declare a complex type with an attribute definition where the
attribute's use is required and a value is specified, the schema validator
allows any value to be specified for the attribute value. My understanding
is that if an attribute has its use specified as required and a value is
specified, then the attribute is mandatory and must have the specified value
(I apologize if I've got this wrong).

Given the following schema definition:

<schema xmlns="http://www.w3.org/1999/XMLSchema">
	<element name="Example" type="ExampleType"/>
	<complexType name="ExampleType">		<element
name="Things" type="ThingsType"/>
	</complexType>
	<complexType name="ThingsType">
		<element name="Thing1" type="Thing1Type" minOccurs="1"/>
		<element name="Thing2" type="Thing2Type" minOccurs="1"/>
		<element name="Thing3" type="Thing3Type" minOccurs="1"/>
	</complexType>

	<complexType name="Thing1Type" base="ThingBase"
derivedBy="extension">
		<attribute name='Name' type='string' use='required'
value='This thing'/>
	</complexType>

	<complexType name="Thing2Type" base="ThingBase"
derivedBy="extension">
		<attribute name='Name' type='string' use='required'
value='That thing'/>
	</complexType>

	<complexType name="Thing3Type" base="ThingBase"
derivedBy="extension">
		<attribute name='Name' type='string' use='required'
value='The other thing'/>
	</complexType>

	<complexType name="ThingBase">
		<element name="foo" type="string"/>
		<element name="bar" type="string"/>
		<element name="baz" type="string"/>
	</complexType>

</schema>	
The following document is parsed with no warnings or errors. As I understand
it, for Thing1, Name must be This thing, for Thing2, Name must be That
thing, etc.

<Example 
	xsi:noNamespaceSchemaLocation="http://localhost/Things.xsd" 
	xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">
	<Things>
		<Thing1 Name="anything">
			<foo/>
			<bar/>
			<baz/>
		</Thing1>
		<Thing2 Name="anything">
			<foo/>
			<bar/>
			<baz/>
		</Thing2>
		<Thing3 Name="anything">
			<foo/>
			<bar/>
			<baz/>
		</Thing3>
	</Things>
</Example>

Also note that attempting to work around the problem using an anonymous type
does not work, i.e.

<complexType name="Thing1Type" base="ThingBase" derivedBy="extension">
	<attribute name='Name' type='string'>		<simpleType
base="string">			<enumeration value="This thing"/>
</simpleType>	</attribute>
</complexType>

--Doug Smith

Re: Bug report: schema attribute value enforcement

Posted by Eric Ye <er...@locus.apache.org>.
According to the schema spec, it indeed seems like this is a bug.  I'll look
into this. We assumed with Schema value constraint "required" should behave
in the same way as with DTD, apparently this assumption should be
questioned.

Eric Ye
IBM-JTC-Silicon Valley.

----- Original Message -----
From: "Smith, Doug" <Do...@fmr.com>
To: <xe...@xml.apache.org>
Sent: Thursday, August 24, 2000 10:23 AM
Subject: Bug report: schema attribute value enforcement


> Greetings,
>
> I'm seeing the following in the xml-xerces_20000822161937.tar.gz source
> distribution:
>
> When I declare a complex type with an attribute definition where the
> attribute's use is required and a value is specified, the schema validator
> allows any value to be specified for the attribute value. My understanding
> is that if an attribute has its use specified as required and a value is
> specified, then the attribute is mandatory and must have the specified
value
> (I apologize if I've got this wrong).
>
> Given the following schema definition:
>
> <schema xmlns="http://www.w3.org/1999/XMLSchema">
> <element name="Example" type="ExampleType"/>
> <complexType name="ExampleType"> <element
> name="Things" type="ThingsType"/>
> </complexType>
> <complexType name="ThingsType">
> <element name="Thing1" type="Thing1Type" minOccurs="1"/>
> <element name="Thing2" type="Thing2Type" minOccurs="1"/>
> <element name="Thing3" type="Thing3Type" minOccurs="1"/>
> </complexType>
>
> <complexType name="Thing1Type" base="ThingBase"
> derivedBy="extension">
> <attribute name='Name' type='string' use='required'
> value='This thing'/>
> </complexType>
>
> <complexType name="Thing2Type" base="ThingBase"
> derivedBy="extension">
> <attribute name='Name' type='string' use='required'
> value='That thing'/>
> </complexType>
>
> <complexType name="Thing3Type" base="ThingBase"
> derivedBy="extension">
> <attribute name='Name' type='string' use='required'
> value='The other thing'/>
> </complexType>
>
> <complexType name="ThingBase">
> <element name="foo" type="string"/>
> <element name="bar" type="string"/>
> <element name="baz" type="string"/>
> </complexType>
>
> </schema>
> The following document is parsed with no warnings or errors. As I
understand
> it, for Thing1, Name must be This thing, for Thing2, Name must be That
> thing, etc.
>
> <Example
> xsi:noNamespaceSchemaLocation="http://localhost/Things.xsd"
> xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">
> <Things>
> <Thing1 Name="anything">
> <foo/>
> <bar/>
> <baz/>
> </Thing1>
> <Thing2 Name="anything">
> <foo/>
> <bar/>
> <baz/>
> </Thing2>
> <Thing3 Name="anything">
> <foo/>
> <bar/>
> <baz/>
> </Thing3>
> </Things>
> </Example>
>
> Also note that attempting to work around the problem using an anonymous
type
> does not work, i.e.
>
> <complexType name="Thing1Type" base="ThingBase" derivedBy="extension">
> <attribute name='Name' type='string'> <simpleType
> base="string"> <enumeration value="This thing"/>
> </simpleType> </attribute>
> </complexType>
>
> --Doug Smith
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-dev-help@xml.apache.org
>
>