XPath.evaluate performance slows down (absurdly) over multiple calls

前端 未结 5 1042
再見小時候
再見小時候 2020-12-08 10:28

I am trying to use the javax.xml.xpath package to run XPath expressions on a document with multiple namespaces, and I\'m having goofy performance problems.

My test d

5条回答
  •  粉色の甜心
    2020-12-08 11:00

    This is a little bit late, but I ran into the same situation, but it seemed like my document was so big that none of the other answers really resolved the problem.

    Eventually, I found jaxen. Once I used it, the document which previously took 15 seconds to parse took mere milliseconds.

    Jaxen is unfortunately rather badly documented, but worked quite well:

    DOMXPath myXPath = new DOMXPath("atom:id/text()");
    String myContent = myXPath.stringValueOf(myDocument);
    

    The Java Doc can be found here http://jaxen.codehaus.org/apidocs/org/jaxen/dom/DOMXPath.html

提交回复
热议问题