Go to file
Helge Hess 4f0f0cbac3 Swift 2 auto convert by Xcode. 2015-06-12 13:20:08 +02:00
SwiftyExpat Swift 2 auto convert by Xcode. 2015-06-12 13:20:08 +02:00
SwiftyExpat.xcodeproj Swift 2 auto convert by Xcode. 2015-06-12 13:20:08 +02:00
SwiftyExpatTests Swift 2 auto convert by Xcode. 2015-06-12 13:20:08 +02:00
.gitignore Ignore xcshareddata 2014-08-05 16:26:26 +02:00
README.md Updated README for Xcode 6.3. 2015-04-09 13:20:06 +02:00

README.md

SwiftyExpat

Simple wrapper for the Expat XML parser. Which had to be adjusted to use blocks instead of function pointer callbacks.

###Targets

Updated to use Swift v0.2 (aka Xcode 6.3).

The project includes two targets:

  • SwiftyExpat
  • SwiftyExpatTests

I suggest you start by looking at the SwiftyExpatTests.

####SwiftyExpat

This is a tiny framework containing the modified Expat parser. Plus a small Swift class to make the API nicer, though this is not really necessary - the block based Expat is reasonably easy to use from Swift.

let p = Expat()
  .onStartElement   { name, attrs in println("<\(name) \(attrs)")       }
  .onEndElement     { name        in println(">\(name)")                }
  .onStartNamespace { prefix, uri in println("+NS[\(prefix)] = \(uri)") }
  .onEndNamespace   { prefix      in println("-NS[\(prefix)]")          }
  .onError          { error       in println("ERROR: \(error)")         }
p.write("<hello>world</hello>")
p.close()

The raw Expat API works like this:

var p = XML_ParserCreate("UTF-8")
XML_SetStartElementHandler(p) { _, name, attrs in println("start tag \(name)") }
XML_SetEndElementHandler  (p) { _, name        in println("end tag \(name)") }

XML_Parse(parser, "<hello/>", 8, 0)
XML_Parse(parser, "", 0, 1)

XML_ParserFree(p); p = nil

You get the idea ...

####SwiftyExpatTests

Just a tiny demo on how to invoke the parser.

###Contact

@helje5 | helge@alwaysrightinstitute.com