Hi, All,
I am using the SAX
parser from xerces-c (version 2.7) to parse XML file. I have one case related
to an attribtue with default value defined in the schema (I pasted the
instance document and the schema in this message). When I parse the
instance document, I noticed the following:
If I turn on
parser validation (for which I use loadGrammar to give the parser the test.xsd),
for the two elements <image>, from the SAX startElement event, I got one
attribtue for each, and have the following
values:
For the first
<image> element:
URI
QName
LocalName
Value
=========================================================================================
http://www.attribute-examples.org src src http://www.xfront.com
=========================================================================================
http://www.attribute-examples.org src src http://www.xfront.com
For the second
<image> element
URI
QName
LocalName
Value
==================================================================================
http://www.attribute-examples.org i:src src http://www.xfront.com/BestPractices.html
==================================================================================
http://www.attribute-examples.org i:src src http://www.xfront.com/BestPractices.html
However, if I turn
off parser validation, I got two attributes for the second <image> element
from the SAX startElement event as below:
URI
QName
LocalName
Value
==================================================================================
http://www.attribute-examples.org i:src src http://www.xfront.com/BestPractices.html
http://www.attribute-examples.org src src http://www.xfront.com
==================================================================================
http://www.attribute-examples.org i:src src http://www.xfront.com/BestPractices.html
http://www.attribute-examples.org src src http://www.xfront.com
I would expect
consistence between the two senarios, am I right?
Thanks
much.
Frank
instance XML
doc
=========
<?xml
version="1.0"?>
<AttributeExamples xmlns="http://www.attribute-examples.org" xmlns:i="http://www.attribute-examples.org" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.attribute-examples.org test.xsd">
<AttributeExamples xmlns="http://www.attribute-examples.org" xmlns:i="http://www.attribute-examples.org" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.attribute-examples.org test.xsd">
<image/> <!--
Using the default value -->
<image i:src=""/'>http://www.xfront.com/BestPractices.html"/> <!-- Not using the default value -->
<image i:src=""/'>http://www.xfront.com/BestPractices.html"/> <!-- Not using the default value -->
</AttributeExamples>
schema
test.xsd
============
<?xml
version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.attribute-examples.org" xmlns="http://www.attribute-examples.org"
elementFormDefault="qualified">
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.attribute-examples.org" xmlns="http://www.attribute-examples.org"
elementFormDefault="qualified">
<xsd:element name="image">
<xsd:complexType>
<xsd:attribute ref="src" default="http://www.xfront.com"/>
</xsd:complexType>
</xsd:element>
<xsd:complexType>
<xsd:attribute ref="src" default="http://www.xfront.com"/>
</xsd:complexType>
</xsd:element>
<xsd:attribute name="src" type="xsd:anyURI"/>
<xsd:element
name="AttributeExamples">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="image" maxOccurs="2"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="image" maxOccurs="2"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
