The attached files mirror the arrangement of a set of libraries I am
currently developing and demonstrate a possible bug in Xerces2-J schema
validation. 

There are two chameleon schemas, one of types and one of structures. The
structures schema includes the types schema. The document schema
(Greeting.xsd) redefines the structures schema, changing an attribute
group originally declared in the types schema.

When Xerces2-J 2.5.0 validates Greeting.xml against Greeting.xsd, a
schema error is given for a circular definition of the attribute group
but the validation proceeds and returns the correct result.

If the content of the types schema is physically included in the
structures schema instead of using xsd:include, there is no error.

As a cross-check, XML Spy behaves as expected.

The behaviour on RedHat Linux 9.0 was as follows:

------

[EMAIL PROTECTED] Greeting]$ java -version
java version "1.4.1_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_02-b06)
Java HotSpot(TM) Client VM (build 1.4.1_02-b06, mixed mode)

[EMAIL PROTECTED] Greeting]$ export CLASSPATH=\
  /usr/local/java/xerces-2_5_0/xercesImpl.jar:\    
  /usr/local/java/xerces-2_5_0/xercesSamples.jar:\
  /usr/local/java/xerces-2_5_0/xml-apis.jar

[EMAIL PROTECTED] Greeting]$ java -Xms64m -Xmx512m dom.ASBuilder -f \
  -a  Greeting.xsd GreetingStructures.xsd GreetingTypes.xsd \
  -i Greeting.xml

[Error] GreetingTypes.xsd:6:44: src-attribute_group.3: Circular
definitions detected for attribute group
':langAttrGroup_fn3dktizrknc9pi'. Recursively following attribute group
references eventually leads back to itself.

[Error] GreetingTypes.xsd:6:44: src-redefine.7.2.1: No attributeGroup in
the redefined schema has a name matching 'langAttrGroup'.

[Error] Greeting.xml:4:14: cvc-complex-type.4: Attribute 'lang' must
appear on element 'Greeting'.

# And the correct behaviour with the workaround:
[EMAIL PROTECTED] Greeting]$ java -Xms64m -Xmx512m dom.ASBuilder -f \
  -a Greeting.xsd GreetingStructures.xsd \
  -i Greeting.xml

[Error] Greeting.xml:4:14: cvc-complex-type.4: Attribute 'lang' must
appear on element 'Greeting'.

-----

Anyone seen similar please, before I submit a bug report.

Thanks

Steve
-- 
Steven J Baker <[EMAIL PROTECTED]>
Ambriel Consulting
<?xml version="1.0"?>

<xsd:schema 
  xmlns:xsd='http://www.w3.org/2001/XMLSchema'
>
  <xsd:include schemaLocation='GreetingTypes.xsd'/>

  <xsd:element name='Greeting' type='GreetingType' />

</xsd:schema>
<?xml version="1.0"?>

<xsd:schema 
  xmlns:xsd='http://www.w3.org/2001/XMLSchema'
>
  <xsd:attributeGroup name='langAttrGroup'>
    <xsd:attribute name='lang' type='xsd:string' use='optional' />
  </xsd:attributeGroup>

  <xsd:complexType name='GreetingType'>
    <xsd:simpleContent>
      <xsd:extension base='xsd:string'>
        <xsd:attributeGroup ref='langAttrGroup' />
      </xsd:extension>
    </xsd:simpleContent>
  </xsd:complexType>

</xsd:schema>
<Greetings xmlns='http://www.example.com'>
  <Greeting lang='en'>Hello World</Greeting>
  <Greeting lang='fr'>Bonjour</Greeting>
  <Greeting >Guten Tag</Greeting>
</Greetings>
<?xml version="1.0"?>

<xsd:schema 
  elementFormDefault='qualified'
  attributeFormDefault='unqualified'
  targetNamespace='http://www.example.com' 
  xmlns='http://www.example.com' 
  xmlns:xsd='http://www.w3.org/2001/XMLSchema'
>


  <xsd:redefine schemaLocation='GreetingStructures.xsd'>

    <xsd:attributeGroup name='langAttrGroup'>
      <xsd:attribute name='lang' type='xsd:string' use='required' />
    </xsd:attributeGroup>

  </xsd:redefine>

  <xsd:element name='Greetings'>
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element ref='Greeting' maxOccurs='5' />
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  
  
</xsd:schema>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to