DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://nagoya.apache.org/bugzilla/show_bug.cgi?id=7471>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=7471 Failed to validate correctly when schema has <xsd:extension> and the base has an attribute Summary: Failed to validate correctly when schema has <xsd:extension> and the base has an attribute Product: Xerces-C++ Version: 1.7.0 Platform: PC OS/Version: Windows NT/2K Status: NEW Severity: Normal Priority: Other Component: Validating Parser (Schema) (Xerces 1.5 or up only) AssignedTo: [EMAIL PROTECTED] ReportedBy: [EMAIL PROTECTED] Schema validation seems to validate incorrectly when a type is defined as an extension of a base type and the base type has an attribute in the element. For example for the following schema extract: <xsd:complexType name="BaseElement"> <xsd:simpleContent> <xsd:extension base="xsd:string"> <xsd:attribute name="myAttribute" type="xsd:string" use="required"/> </xsd:extension> </xsd:simpleContent> </xsd:complexType> <xsd:complexType name="ExtendingElement"> <xsd:simpleContent> <xsd:extension base="BaseElement"/> </xsd:simpleContent> </xsd:complexType> the validating parser will complain with the following error: Attribute '{}myAttribute' is not declared for element 'Extend' for the following element in an XML instance (which the type of the element is "ExtendingElement", defined in xsd): <Extend myAttribute="1">ab</Extend> In contrast, if the type of the element is "BaseElement", validation went through ok. e.g. the following element instance: <Base myAttribute="1">ab</Base> This was observed in SAX2. Unsure if it happens in DOM or SAX1. It is reported in version 1.7.0 and it was also observed in version 1.6.0. This can be replicated by using the sample program SAX2Print.exe provided in the distribution. The following describes how to replicate it: * Copy the text between "----start xsd----" and "----end xsd---" at the end of this description and save it to file "c:\temp\mytest.xsd". * Copy the text between "----start xml base element----" and "----end xml base element----" at the end of this description and save it to file "c:\temp\mytestBase.xml". * Copy the text between "----start xml extend element----" and "----end xml base element----" at the end of this description and save it to file "c:\temp\mytestExtend.xml". * Run the sample program SAX2Print.exe with one parameter: "C:\temp\mytestExtend.xml". It will result in a validation error: Attribute '{}myAttribute' is not declared for element 'Extend'. Unexpected behavior. * Run the sample program SAX2Print.exe with one parameter: "C:\temp\mytestBase.xml". It does not result in a validation error. Expected behavior. Or if it is easier, the three files (mytest.xsd, mytestBase.xml and mytestExtend.xml) can be downloaded in a zip file from http://homepages.ihug.co.nz/~ric/mytest.zip. It will stay in this url until end of April 2002. You may need to change the location of the schema defined in the xml messages if mytest.xsd is not saved in c:\temp. Both mytestExtend.xml and mytestBase.xml pass the schema validation by XMLSpy 4.0. As a further experiment, you may remove "myAttribute" attibute in mytestExtend.xml and re-run the test. SAX2Print.exe will not (incorrectly) return with a validation error. In contrast, XMLSpy 4.0 will complain with a validation error with "myAttribute" removed from mytestExtend.xml. ----------------- start xsd -------------------- <?xml version="1.0"?> <xsd:schema targetNamespace="urn:myNamespace" xmlns="urn:myNamespace" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:complexType name="BaseElement"> <xsd:simpleContent> <xsd:extension base="xsd:string"> <xsd:attribute name="myAttribute" type="xsd:string" use="required"/> </xsd:extension> </xsd:simpleContent> </xsd:complexType> <xsd:complexType name="ExtendingElement"> <xsd:simpleContent> <xsd:extension base="BaseElement"/> </xsd:simpleContent> </xsd:complexType> <xsd:complexType name="RootElement"> <xsd:sequence> <xsd:choice> <xsd:element name="Base" type="BaseElement"/> <xsd:element name="Extend" type="ExtendingElement"/> </xsd:choice> </xsd:sequence> </xsd:complexType> <xsd:element name="mytestXML" type="RootElement"/> </xsd:schema> ----------------- end xsd -------------------- ----------------- start xml base element -------------------- <?xml version="1.0"?> <test:mytestXML xmlns:test="urn:myNamespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:myNamespace C:\temp\mytest.xsd"> <Base myAttribute="1">ab</Base> </test:mytestXML> ----------------- end xml base element -------------------- ----------------- start xml extend element -------------------- <?xml version="1.0"?> <test:mytestXML xmlns:test="urn:myNamespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:myNamespace C:\temp\mytest.xsd"> <Extend myAttribute="1">ab</Extend> </test:mytestXML> ----------------- end xml extend element -------------------- --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]