O'Reilly logo

Swift Essentials by Dr. Alex Blewitt

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

Although JSON is more commonly used, there are still many XML-based network services. Fortunately, XML parsing has existed in iOS since version 5 in the NSXMLParser class and is simple to access from Swift. For example, some data feeds (such as blog posts) use XML documents such as Atom or RSS.

The NSXMLParser is a stream-oriented parser; that is, it reports individual elements as they are seen. The parser calls the delegate to notify when the elements are seen and have finished. When an element is seen, the parser also includes any attributes that were present; for text nodes, it includes the string content.

Thus, the parsing of an XML file involves some state management in the parser. The example used in this section will parse an ...

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