Parsing XML with SAX

See the source image

what does sax stand for : Simple API for XML. In real life you will want to use the SAX parse to process data and then use that data , as you wish.

When should we use SAX ? : Well , as previously we pointed out you want to use SAX when you convert existing xml to data. The key to the conversion process is to deliver SAX events as it reads the data.

SAX is efficient and fast , but with its event model makes it more useful for such state independent filtering.

See the source image

What’s independent filtering ? well, simply put it means that it does not depend on the elements that have come before it.

On the other hand if you have state dependent , you may want to utilize a pull parser API such as STAX .

With STAX you can read data from an xml file , track that data as is being collected , read cdata and its events.

Another incredible benefit of using SAX is that if you encounter a problem from an xml file.

for example : Tags that doesn’t match . You can still collect data from the xml file up to where that error code in the xml is encountered.

See the source image

Citation : David Gassner , Parsing Xml files using SAX , DOCS_ORACLE https://docs.oracle.com/javase/tutorial/jaxp/sax/parsing.html how to java :https://howtodoinjava.com/xml/sax-parser-read-xml-example/

Leave a comment