I've recently been
tinkering with the effeciency of a process I have to take an XML document and
apply a lot of XPATH expressions to the XML.
Here is what I've
done to maximize the effeciency of this process. Hoping others will have other
handy tricks up their sleeves or point out any
glaring deficiency.
The basic algorithm
of the process is this:
1. Build a Map of
the XPATH's to apply to the XML. The xpath expression is
cached as org.jdom.xpath.XPath objects
2. For each XML
document to apply the Map of xpath expressions to
3. Build the Document object from the XML
string
4. Loop
through the Map of XPath objects and apply each to the
message.
5 Next XML
document
The things I've done to increase performance
are:
1. Cached
the xpath expressions as org.jdom.xpath.XPath objects
2. Ensure
the use of the SAXParser,
org.apache.xerces.parsers.SAXParser
3. Make
each xpath expression as effecient as possible. For example, use
/*/*/MyElement instead of //MyElement.