Parsing big XML files using SAX parser (skip some lines/tags)

Amine picture Amine · Aug 5, 2010 · Viewed 7.6k times · Source

I am currently developing an app that retrieves data from the internet using SAX. I used it before for parsing simple XML files like Google Weather API. However, the websites that I am interested in take parsing to the next level. The page is huge and looks messy. I only need to retrieve some specific lines; the rest is not useful for me.
Is it possible to skip those useless lines/tags, or do I have to go step by step?

Answer

raja kolluru picture raja kolluru · Aug 5, 2010

I like commons-digester. It allows you to specify rules against particular tags. The rule gets executed only when the tag is encountered.

Digester is built over sax and hence has all the sax features plus the specificity that is required for selectively parsing specific tags. It also uses a stack that is pushed with new elements as and when the corresponding tag is encountered and is popped when the element ends.

I use it for parsing all my configuration files.

Check out digester at http://commons.apache.org/digester/