Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6564400

setIgnoringContentElementWhitespace doesn't work with XSD (did in 1.5)

XMLWordPrintable

    • x86
    • windows_xp

      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&#39;>
        <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.

            nwalshsunw Norman Walsh (Inactive)
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: