Difference between Dom4J & SAX parser? When to prefer Dom4J in Talend?

Difference between Dom4J & SAX parser? When to prefer Dom4J in Talend?

Hello All,
I would like to know technical difference between the two Generation Modes (Advanced Settings of tFileInputXML)
1. Slow & Memory Consuming (Dom4J).
2. Fast with low Memory Consumption (SAX).

In which scenarios, one should prefer Dom4J (Slow) over SAX (Fast) generation modes? Need your expert advice.
Seventeen Stars

Re: Difference between Dom4J & SAX parser? When to prefer Dom4J in Talend?

hi vikram.takkar,
Dom4j load the entire document to be able to work with. (lot of memories)
Sax parser just retrieve what you need.
So for huge xml files, you'll use Sax, because Dom4j need a lot of memory to work with.
If you have to use filter in your Xpath , only Dom is Ok. Sax doesn't !
regards
laurent
Seventeen Stars

Re: Difference between Dom4J & SAX parser? When to prefer Dom4J in Talend?

about tExtractXmlField, the parser is automatically on Document Parser (Dom4j).
So you cannot use it for huge data.
@+
Employee

Re: Difference between Dom4J & SAX parser? When to prefer Dom4J in Talend?

Dom4j: it will load the whole source xml file and construct a tree in the computer's memory. When the source file is big, it will spend lots of time to load the source file into the memory. Advantatage is that it support plenty of xpath expressions.
SAX: it is based on data stream. like read data from a source file using java io stream, it won't consume a little memory; especially when the xpath doesn't include "..", it will process the xml source very quickly with few memory. disadvantages: it only supports simple xpath and doesn't support complex xpath expressions like last() and filter and so on.

Re: Difference between Dom4J & SAX parser? When to prefer Dom4J in Talend?

Thanks Kzone and Wliu for your comments.
I have published a small article on the difference between Slow & Memory Consuming (Dom4J) and Fast with low Memory Consumption (SAX) Generation modes.
For details visit http://www.vikramtakkar.com/2013/09/difference-between-dom4j-and-sax-parser.html