Under The Bridge Under The Bridge

Tag: XML
Code: AQXMLParser

Got a big (like, 22 MB) XML file to parse on the iPhone? Want to reduce the memory usage from NSXMLParser’s huge (like, 123 MB) virtual memory usage by several orders of magnitude down to almost nothing (like, 68 kb)?

Yeah, we thought you did.

The magic trick is to use “Alan Quatermain”s AQXMLMemoryParser:

Here’s the output. I think it shows that AQXMLParser is going to be *lovely* for the iPhone. Mwa-ha-haa.

Testing NSXMLParser from URL...
Parsed 200000 numbers
Peak VM usage: 128991232 bytes

Testing NSXMLParser with mapped data...
Parsed 200000 numbers
Peak VM usage: 130035712 bytes

Testing AQXMLParser...
Parsed 200000 numbers
Peak VM usage: 69632 bytes

That’s right, the NSXMLParser variant (calling xmlParseChunk() with all data at once) uses 123-124MB, while AQXMLParser (calling xmlParseChunk() with 1KB at a time, not loading all data anywhere) gets 68KB.

In short: AQXMLParser == T3h w1n!

Indeed. Source is in AQToolKit on github which is just full of all sorts of other useful goodies as well.

h/t: iPhone Development!


Tutorial: JSON over HTTP

We’ve mentioned the json-framework project before; but here’s an excellent tutorial on how exactly to use it that you really should not miss if that’s something you need to do.

h/t: iPhoneKicks!

Sample Code: RSS Reader

Here’s a little tutorial of possible utility; how to build an RSS reader for the iPhone!

Whilst that is a pretty straightforward thing to do, this is a little interesting in that it demonstrates the use of NSXMLParser, flying in the face of what appears to be conventional wisdom that one should rely on the cross-platform libxml2 for their XML-parsing iPhone development projects. And people have gone to some work to make that easier with the TouchXML library which, in case we didn’t mention it in our earlier report, is part of the ever more useful touchcode repository over at Google Code.

‘Course, either of the above — or for that matter, anything at all — are probably better than the last time we had to get into that XML parsing thing a lot, which was struggling to make Xerces work in a large cross-platform source base. There were some very … interesting … issues trying to get wchar-based Windows twaddle and OS X style (also known as the “correct” or “real”, type) of characters to work together. Yeeesh. Well out of that, we are!