What is the fastest way to query a huge XML file in java,
DOM - xpath : this is taking lot of time,
DocumentBuilderFactory 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);
//this line takes lot of time
NodeList result = (NodeList)expr.evaluate(document, XPathConstants.NODESET);
with last line in code, program finishes in 40 secs and without it in 1 second.
SAX : I don't know if this can be used for query, on internet I am only able to find the examples of parsing.
What are the other options to make query faster, the size of my xml file is around 5MB. Thnx