A lightweight XML parser for iOS
Check out SMXMLDocument on Github.
If you’ve ever tried to parse XML on the iPhone or iPad
NSXMLParser, you may have wondered if
you’re taking crazy pills.
Is this really how people parse XML on iOS? Really?
I mean, yes, it’s true that using
NSXMLParser forces you to write extremely efficient
stream-based parsing without buffering the entire XML structure in
But it also forces you, the savvy developer who already hates XML, to hate it even more as you write tons of conditional code and temporary classes so you can manually keep track of state.
When we wrote our first iOS app, Style.com, we looked around for XML-parsing alternatives on iOS, and there are quite a few. But they all felt like…too much.
What we really wanted was just the simplest possible class that
NSXMLParser itself to build up an
easily-traversable Cocoa object hierarchy.
So we made one. It’s a single class, with like one page of code.
And we find it very pleasant to use:
We’ve used this class to parse XML on iOS for years now, and
we’ve never had any problems. You may want to fallback to
NSXMLParser if you have to deal with a multi-megabyte
XML document though.