Parsing XML

We’ve downloaded the XML as a Data object, and created two structs to hold the useful parts of that data. Now the question is how we go through the data to populate those structures. The way we do this is to use a parser, an object that understands the syntax and structure of XML. The parser can walk through the tree-structured XML data and expose its element names, attributes, text, parent-child attributes, and so on.

As we might expect from a modern computing platform, the iOS SDK does have built-in parsing for XML, in the form of Foundation’s XMLParser class.

XMLParser is an event-driven parser, rather than a document-oriented parser like you might be used to from working with the DOM of a web page. The difference is that instead ...

Get iOS 10 SDK Development, 1st Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.