Monday 15 August 2011

query xml using xpath in java -


I'm trying to do some inquiries on the huge XML file in Java in the xpath, here's my code: Document Builder Factor docBuilderFactory = DocumentBuilderFactory.newInstance (); DocBuilderFactory.setNamespaceAware (true); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder (); Document document = docBuilder.parse (new file ("test.xml")); XPath xpath = XPathFactory.newInstance (). NewXPath (); String xpath = "/ * / * [@ id = 'ABCD'] / * / *"; XPathExpression expr = xpath.compile (xPath); Nodelist result = (node ​​list) expr.evaluate (document, XPathConstants.NODESET);

The last line of the code takes a lot of time, I do not know, when this line is finished with a program in 1 second and with it in 40 seconds. I also tried XOM, which is not working. What is the option to make fast queries in a huge XML file in Java?

Use SX, not DOM. Because SAX requires very little memory compared to DOM, because SAX does not create internal representation of XML data (tree structure), because a DOM does, instead SAX only sends the data to the application because it reads goes; Your application can do that, who sees that data, wants to do it as well.



No comments:

Post a Comment