Skip to content

tayloraswift/swiftxml

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SwiftXML

Language Issues License Build Queen

Lightweight XML parsing in pure Swift 3. No Foundation. No dependencies.

SwiftXML doesn’t wrap anything. It parses XML directly, character by character. And the API is simple and easy to use. In fact, it exposes just two objects — a protocol and a function:

protocol Parser
{
    func handle_data(data:[UnicodeScalar])
    func handle_starttag(name:String, attributes:[String: String])
    func handle_startendtag(name:String, attributes:[String: String])
    func handle_endtag(name:String)
    func error(_:String, line:Int, column:Int)
}
func parse(_:String, parser:Parser)

SwiftXML will tokenize your XML string into tags and data. It does not build any tree structures; that is for you to implement. Nor does it read files from disk into memory; that is for the Swift standard library to implement (hint hint @ Swift standard library devs).

See the swiftxmlTests.swift file for a usage example, if you are still confused.