United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-6564400 : setIgnoringContentElementWhitespace doesn't work with XSD (did in 1.5)

Details
Type:
Bug
Submit Date:
2007-06-01
Status:
Closed
Updated Date:
2012-06-09
Project Name:
JDK
Resolved Date:
2007-07-13
Component:
xml
OS:
windows_xp
Sub-Component:
jaxp
CPU:
x86
Priority:
P3
Resolution:
Duplicate
Affected Versions:
6
Fixed Versions:

Related Reports
Duplicate:
Relates:

Sub Tasks

Description
FULL PRODUCT VERSION :
java version "1.6.0_01"
Java(TM) SE Runtime Environment (build 1.6.0_01-b06)
Java HotSpot(TM) Server VM (build 1.6.0_01-b06, mixed mode)



ADDITIONAL OS VERSION INFORMATION :
Linux 2.6.9-42.0.10.ELsmp #1 SMP Fri Feb 16 17:17:21 EST 2007 i686 i686 i386 GNU/Linux

A DESCRIPTION OF THE PROBLEM :
In 1.5, when validating an xml document against a schema, if DocumentBuilderFactory.setIgnoringElementContentWhitespace(true) was used the parser would remove all of the extraneous whitespace.  However, in 1.6 it no longer works like this (though setIgnoringComments() still works).  The following code run under 1.5 and 1.6 provide very different results:

File schemaFile = new File("test.xsd");
 
// Now attempt to load up the schema
Schema schema = null;
SchemaFactory schFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
schema = schFactory.newSchema(schemaFile);
 
File xmlFile = new File("test.xml");
 
// Set the options on the DocumentFactory to remove comments, remove whitespace
// and validate against the schema.
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
docFactory.setIgnoringComments(true);
docFactory.setIgnoringElementContentWhitespace(true);
docFactory.setSchema(schema);
 
DocumentBuilder parser = docFactory.newDocumentBuilder();
Document xmlDoc = parser.parse(xmlFile);


Here is the sample XML:

<Person>
        <FirstName>Doofus</FirstName><!-- MONKEY -->
        <LastName>McGee</LastName>
</Person>


Here is the sample schema:

<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
  <xsd:element name='Person' type='PersonType'/>
  <xsd:complexType name='PersonType'>
                <xsd:sequence>
                        <xsd:element name='FirstName' type='xsd:string'/>
                        <xsd:element name='LastName' type='xsd:string'/>
                </xsd:sequence>
        </xsd:complexType>
</xsd:schema>


In 1.5, it correctly removes the extraneous whitespace nodes and in 1.6 it does not. Java 1.5 gives me:

NODE: Person   TYPE: element   VALUE:
  NODE: FirstName   TYPE: element   VALUE:
    NODE: #text   TYPE: text   VALUE: Doofus
  NODE: LastName   TYPE: element   VALUE:
    NODE: #text   TYPE: text   VALUE: McGee


Java 1.6 gives me:

NODE: Person   TYPE: element   VALUE:
  NODE: #text   TYPE: text   VALUE:
  NODE: FirstName   TYPE: element   VALUE:
    NODE: #text   TYPE: text   VALUE: Doofus
  NODE: #text   TYPE: text   VALUE:
  NODE: LastName   TYPE: element   VALUE:
    NODE: #text   TYPE: text   VALUE: McGee
  NODE: #text   TYPE: text   VALUE:


Both versions correctly remove the comments but only 1.5 removes the whitespace.


REPRODUCIBILITY :
This bug can be reproduced always.

Release Regression From : 5.0u11
The above release value was the last known release where this 
bug was not reproducible. Since then there has been a regression.

                                    

Comments
EVALUATION

I can't explain why the behavior changed from 1.5 to 1.6, but I'm afraid I think the current behavior is the correct behavior.

The problem is that "element content whitespace" is true if and only if the infoset [element content whitespace] property is true. When DTD validation occurs, the parser sets the element content whitespace property to true on whitespace that it encounters in element content.

Unfortunately, schema validation is not defined to change the [element content whitespace] infoset property. Nor does it provide an equivalent property (at least not that I recall).

I'm concerned that this is a regression, but I don't know what to do about it.
                                     
2007-06-08
EVALUATION

I've checked in a fix that corrects the problem. Please see CR6545684 for more details.
                                     
2007-07-13



Hardware and Software, Engineered to Work Together