DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://nagoya.apache.org/bugzilla/show_bug.cgi?id=7696>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=7696 Whitespace Text nodes in DOM when validating with schema and ignoreWhitespace == true Summary: Whitespace Text nodes in DOM when validating with schema and ignoreWhitespace == true Product: Xerces2-J Version: 2.0.1 Platform: PC OS/Version: Linux Status: NEW Severity: Normal Priority: Other Component: XML Schema Structures AssignedTo: [EMAIL PROTECTED] ReportedBy: [EMAIL PROTECTED] When parsing an XML doc and using an XML schema for validation, calling DocumentBuilderFactory.setIgnoringElementContentWhitespace(false) does not prevent whitespace text nodes from appearing in the DOM tree. These whitespace text nodes do not appear when validating with a DTD. Included here are my test application and files: XSDTest.java --------------------------------- import javax.xml.parsers.*; import org.w3c.dom.*; import org.xml.sax.*; public class XSDTest { public static final String xsdfile = "test.xsd"; public static final String xmlfile1 = "test_dtd.xml"; public static final String xmlfile2 = "test_xsd.xml"; public static void main(String args[]) { String xmlfile = xmlfile1; try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setCoalescing(true); factory.setIgnoringElementContentWhitespace(true); factory.setIgnoringComments(true); factory.setNamespaceAware(true); factory.setValidating(true); if(args.length > 0 && args[0].equals("-s")) { xmlfile = xmlfile2; factory.setAttribute("http://apache.org/xml/features/validation/schema", new Boolean(true)); factory.setAttribute("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation", xsdfile); } DocumentBuilder builder = factory.newDocumentBuilder(); builder.setErrorHandler(new ErrorHandler() { public void error(SAXParseException e) { e.printStackTrace(); } public void fatalError(SAXParseException e) { e.printStackTrace(); System.exit(1); } public void warning(SAXParseException e) { e.printStackTrace(); } }); Document doc = builder.parse(xmlfile); NodeList list = doc.getDocumentElement().getChildNodes(); for(int i=0; i < list.getLength(); i++) { Node node = list.item(i); System.out.println(node.getNodeName()); } }catch(Exception e) { e.printStackTrace(); } } } test_dtd.xml ------------------------ <?xml version="1.0"?> <!DOCTYPE testxml SYSTEM "test.dtd"> <testxml> <foo>foo</foo> <bar>bar</bar> </testxml> test.dtd ----------------------- <!ELEMENT testxml (foo , bar)> <!ELEMENT foo (#PCDATA)> <!ELEMENT bar (#PCDATA)> test_xsd.xml ----------------------- <?xml version="1.0"?> <testxml> <foo>foo</foo> <bar>bar</bar> </testxml> test.xsd ---------------------- <?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="testxml"> <xs:complexType> <xs:sequence> <xs:element name="foo" type="xs:string"/> <xs:element name="bar" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> Output of "java -cp . XSDTest" ---------------------------- /users/cgreco/data/src/test>java -cp . XSDTest foo bar Output of "java -cp . XSDTest -s" --------------------------------- /users/cgreco/data/src/test>java -cp . XSDTest -s #text foo #text bar #text --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
