这发生在施工时间:
documentBuilderFactory dbFactory = documentBuilderFactory.newInstance();documentBuilder dBuilder = this.dbFactory.newdocumentBuilder(); XPathExpression[] ex = new XPathExpression[]{about 30 different Expressions}XPathExpression mainEx =xPath.compile("/rootElement/firstLevel/secondLevel");
那么代码:
document doc = this.dBuilder.parse("somefile.xml");//took 20 ms until hereNodeList nodes = (NodeList) mainEx .evaluate,doc,XPathConstants.NODESET); //took another 20 ms until here !!! for (int i = 0; i < nodes.getLength(); i++) { Node n = nodes.item(i); for (XPathExpression e:ex) { String v = (String) e.evaluate(n,XPathConstants.STRING); if (v != null) { System.out.println(v); } } } //this only takes 5 ms解决方法 您可能会遇到我在此处记录的这个问题:
Java XPath (Apache JAXP implementation) performance
基本上,您应该添加这些JVM参数以大大加快Xalan的XPath实现:
-Dorg.apache.xml.dtm.DTMManager= org.apache.xml.dtm.ref.DTMManagerDefault
要么
-Dcom.sun.org.apache.xml.internal.dtm.DTMManager= com.sun.org.apache.xml.internal.dtm.ref.DTMManagerDefault总结
以上是内存溢出为你收集整理的优化DOM和XPath Java代码全部内容,希望文章能够帮你解决优化DOM和XPath Java代码所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)