Why Do I Need SAX?
If you have an XML document, at some point you will need to read it programmatically. Let’s say you want to pull out the text from a document or maybe look for attributes of specific tags. You might be able to do some of the work using a tool or maybe XSLT, but these solutions have their limitations. When you need to do something more complex, you’ll have to write a program. That’s where SAX comes in.
If you are writing a tool or a standalone program to process XML, SAX is a good way to do it. Many applications today can be customized using an XML file. These files have replaced the traditional “properties” files for reasons of uniformity and richness of expression. Instead of spending a lot of your time writing a parser to read XML files, you might as well use SAX. As mentioned earlier, SAX is completely free, so it can be embedded in a larger application without royalty fees or even copyright notices.
Some SAX parsers can validate a document against a Document Type Definition (DTD). Validating parsers can also tell you specifically where validation has failed. You will see an example demonstrating how to do that in this chapter.