Go to file
Helge Heß cfb8c1b501 Merge branch 'release/1.6.0' 2014-08-30 13:10:20 +02:00
SwiftyExpat The + operator doesn't work with String+Character anymore in b6 2014-08-30 13:07:51 +02:00
SwiftyExpat.xcodeproj Dropped bridging header, made all Expat headers public (let's reduce it once it's working) 2014-07-22 19:19:41 +02:00
SwiftyExpatTests Beauty. 2014-07-15 20:08:44 +02:00
.gitignore Ignore xcshareddata 2014-08-05 16:26:26 +02:00
README.md Beauty. 2014-07-15 20:08:44 +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

The project includes two targets:

  • SwiftyExpat
  • SwiftyExpatTests

I suggest you start out 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