Latest 0.3.0
Homepage https://github.com/hironytic/XMLPullitic
License MIT
Platforms ios 8.0, requires ARC
Authors

CI Status
Version
License
Platform
Carthage compatible

Swifty XML pull parser

Usage

let xml = "<?xml version="1.0" encoding="UTF-8" ?><foo>Hello World!</foo>"
if let parser = XMLPullParser(string: xml) {
    do {
        parsing: while true {
            switch try parser.next() {
            case .startDocument:
                print("start document")
            case .startElement(let name, _, _):
                print("start element: (name)")
            case .characters(let text):
                print("text: (text)")
            case .endElement(let name, _):
                print("end element: (name)")
            case .endDocument:
                print("end document")
                break parsing
            }
        }
    } catch let error {
        print("error: (error)")
    }
}

Thanks to swift’s pattern matching feature, you can easily handle start of elements like this:

let event = try parser.next()
switch event {
case .startElement("foo", _, _):
    // handle start of <foo>
    print("foo: (event)")
case .startElement("bar", _, _):
    // handle start of <bar>
    print("bar: (event)")
case .startElement("baz", "http://example.com/ns/1.0"?, let element):
    // handle start of <baz>, whose namespace URI is http://example.com/ns/1.0
    // note: you must set parser.shouldProcessNamespaces true to handle namespaces

    // you can get attributes from XmlElement object
    print(element.attributes["xyz"])
case .startElement(_, _, _):
    // handle start of other elements
    print("other: (event)")
default:
    break
}

Requirements

  • iOS 8.0+
  • Swift 3.0+

Installation

CocoaPods

XMLPullitic is available through CocoaPods.
To install it, simply add the following lines to your Podfile:

use_frameworks!
pod "XMLPullitic"

Carthage

XMLPullitic is available through Carthage.
To install it, simply add the following line to your Cartfile:

github "hironytic/XMLPullitic"

Author

Hironori Ichimiya, [email protected]

License

XMLPullitic is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "XMLPullitic",
    "version": "0.3.0",
    "summary": "Swifty XML pull parser",
    "description": "This pod provides an XML pull parser.",
    "homepage": "https://github.com/hironytic/XMLPullitic",
    "license": "MIT",
    "authors": {
        "Hironori Ichimiya": "[email protected]"
    },
    "source": {
        "git": "https://github.com/hironytic/XMLPullitic.git",
        "tag": "v0.3.0"
    },
    "platforms": {
        "ios": "8.0"
    },
    "requires_arc": true,
    "source_files": "Sources/**/*",
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This