Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Did setIgnoringElementContentWhitespace quit working in 1.6?! Is it a bug?

843834May 25 2007 — edited Jul 19 2007
I'm desperate for some help here. I know it looks like a long post but it really isn't. Basically, I have some code that works find in 1.5 but now is broken in 1.6. Here is the code (error handling, etc. has been removed):
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:
Can anyone tell me why this is happening? Both versions correctly remove the comments but only 1.5 removes the whitespace. This definitely seems like a bug to me.

Message was edited by:
MePaco
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 16 2007
Added on May 25 2007
6 comments
947 views