April 2015
Intermediate to advanced
556 pages
17h 47m
English
There are two standard approaches to parsing XML. The high-level method (DOM parsing) is to use NSXMLDocument and NSXMLNode. If you have an NSData object containing the following XML:
<?xml version="1.0" encoding="UTF-8"?>
<people>
<person>
<first>Patrick</first>
<last>Robinson</last>
</person>
</people>
NSXMLDocument will parse it into a handy tree (Figure 28.7):
Figure 28.7 Parsed XML document
You can then traverse the tree manually or use XPath queries to extract the nodes you want. For example, the following listing prints all of the first names from the given XML document:
Read now
Unlock full access