The two widely used methods for parsing an XML document are SAX and DOM. A SAX (Simple API for XML) parser is event-driven. It reads the XML document incrementally and calls a delegate method whenever it recognizes a token. Events are generated at the beginning and end of the document, and the beginning and end of each element. A DOM (Document Object Model) parser reads the entire document and forms a tree-like corresponding structure in memory. You can then use the XPath query language to select individual nodes of the XML document using a variety of criteria.
Most programmers find the DOM method more familiar and easier to use; however, SAX-based applications are generally more efficient, run faster, and use less memory. So, unless you are constrained by system requirements, the only real factor when deciding to use SAX or DOM parsers comes down to preference.
If you want to know more about XML, I recommend Learning XML, Second Edition by Erik T. Ray (O’Reilly) as a good place to start.
We met the libxml2 parser and Matt Gallagher’s XPath wrappers in the preceding chapter, and my advice is to use these wrappers if you want to do DOM-based parsing of XML on the iPhone or iPod touch.
The wrappers offer two methods. The only difference between the two is that one expects an HTML document and is therefore less strict about what constitutes ...