I have some problem when try to parse an XML file.
Here is my code.
When compile and run with jdk 1.4 there is no problem.Code:package app.test; import java.io.*; import javax.xml.parsers.*; import org.w3c.dom.*; import org.xml.sax.*; public class BasicDom { public static void main(String[] args) { Document doc = parseXmlFile("test.xml", false); System.out.println("Document = "+doc); } // Parses an XML file and returns a DOM document. // If validating is true, the contents is validated against the DTD // specified in the file. public static Document parseXmlFile(String filename, boolean validating) { try { // Create a builder factory DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(validating); // Create the builder and parse the file Document doc = factory.newDocumentBuilder().parse(new File(filename)); return doc; } catch (SAXException e) { // A parsing error occurred; the xml input is not valid } catch (ParserConfigurationException e) { } catch (IOException e) { } return null; } }
But when compile and run with jkd 1.5 it show null document.Code:Document = org.apache.crimson.tree.XmlDocument@150bd4d
Does anyone know what is the problem when try to use jdk1.5?Code:Document = [#document: null]


Reply With Quote
Bookmarks