O'Reilly logo

Mastering Swift by Jon Hoffman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Parsing XML documents

For parsing XML documents, perform the following steps:

  1. Create a class that will conform to the NSXMLParaseDelegate protocol. Let's name the class MyXMLParser. The MyXMLParser class definition will look like this:
    class MyXMLParser: NSObject, NSXMLParserDelegate {
    
    }
  2. Next, we will need to add three properties that will be used by the parser while it is parsing the document. These three properties are as follows:
    • books: This property will be an optional array that will contains the list of books defined in the XML document
    • book: This will be an optional instance of the Book class that represents the current book being parsed within the XML document
    • elementData: This will be an instance of the string class that contains the value ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required