Reputation: 21897
I've a big XML data returned by SAP. Of this, I need only few nodes, may be 30% of the returned data.
After googling, I got to know that I can filter the nodes in either of the ways:
Apply XSLT templates - Have seen some nice solutions, which i want, in this site only.
Using a parser - use JDOM or SAX parser.
which is the efficient way to "filter XML nodes"?
thanks
Upvotes: 2
Views: 2249
Reputation: 20794
If your employer can afford SAP, then they certainly can afford Saxon, which is an XSLT processor that can process streams of arbitrary length.
Upvotes: 0
Reputation: 108969
The StAX API may suit your needs - have a look at StreamFilter or EventFilter. It has an advantage over SAX in that its pull model makes it is easier to quit processing when you've parsed all the data you want without resorting to artificial mechanisms like throwing an exception.
Upvotes: 2
Reputation: 625347
SAX parser will be the fastest and most efficient (in that you don't need to read the entire document into memory and process it).
XSLT will be probably a terser solution since all you need is an identity transform (to copy the input document) with a few templates to copy out the bits you want.
Personally I'd go with the SAX parser.
Upvotes: 4