I’m working on a SOA project that handles a lot of XML messages.
Every message that goes through the system will be logged.
To make it uniform all messages are transformed to SOAP messages,
and when receiving SOAP messages we need to get the important fields
from a message in order to log these.
I used the JAMon tool to monitor the performance of handling these messages, and it turned out that the parsing of XML with XPath and Java 5 took (relatively) much time. Parsing a message took 19ms on average. And we already cached the XPathExpression.
It’s a very simple XML message with 1 root element and 10 child elements.
I needed to extract the value of 8 of these elements.
I tried to rebuild the XPath expression with different methods for extracting fields from an XML document with the following results:
Traversing with DOM: 21 times as fast
Using JDOM: 17 times as fast
Using indexOf string manipulation: 881 times as fast!
So using indexOf to extract fields in XML documents can be much faster!