views:

146

answers:

4

Hi All,

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:

  1. Apply XSLT templates - Have seen some nice solutions, which i want, in this site only.

  2. Using a parser - use JDOM or SAX parser.

which is the efficient way to "filter XML nodes"?

thanks

+3  A: 

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.

cletus
A: 

Of course SAX parser. http://stackoverflow.com/questions/373833/best-xml-parser-for-java

adatapost
+1  A: 

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.

McDowell
A: 

If your employer can afford SAP, then they certainly can afford Saxon, which is an XSLT processor that can process streams of arbitrary length.

Steven Huwig