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