TBXML released
Hi all. Sorry for not posting much at the moment and for the distinct lack of tutorials. Things are hectic both at work and with the book. That said I wanted to post tonight about TBXML.
TBXML is a great lightweight XML parser tool that has been created by Tom Bradley. Tom is a reader of this blog and a friend who has been helping me test the code I’m putting together for Sir Lamorak’s Quest and get to the bottom of some really crappy bugs I’ve faced.
During testing it was becoming clear that KissXML was too slow when parsing the Tiled tmx XML file. With a large map of around 200 tiles and 3 layers, it was taking around 20 seconds to load and parse the file. I really didn’t want to be limited to small tmx files which the slow parsing was forcing me to consider.
Having spent some time looking at this with Tom he decided he would create his own XML document parser that would be built for speed and with a simple API. What he has come up with is TBXML.
Intro from the TBXML website
TBXML is a light-weight XML document parser written in Objective-C designed for use on Apple iPhone / iPod Touch devices. TBXML aims to provide the fastest possible XML parsing whilst utilising the fewest resources. This requirement for absolute efficiency is achieved at the expence of XML validation and modification. It is NOT possible to modify and generate valid XML from a TBXML document and NO validation is performed whatsoever whilst importing and parsing an XML document.
Having implemented this into the Tiled class the difference is speed is truly amazing. The TMX file I was passing was taking between 15-20 seconds and with the new parser its down to 600ms meaning I can handle pretty much any map size I want. It also supports gzip as well meaning that the contents of the tmx file can be gzipped, a feature of the Tiled map editor. This brought the file size down from almost 2MB to 4KB.
I will post the changes to the Tiled map file ASAP so that you can see how the parser is being used. I’ve also added Object Group support into the class as well. I’m not sure I’ll have time to back port it into the tutorial code stream but I’ll see what I can do :o)
I can’t thank Tom enough for his parser and if you need to parse an XML document quickly and don’t need to create or write to an XML document then this parser is for you.
I hope you find it as useful as I have.
Thanks Tom
Mike
8 Comments
Gregorski on September 27th, 2009
Mike, have you considered that XML might be overkill for this and it would probably be much faster to transform the XML into a really simple CSV file and parse it manually ?
Sure it’s not as elegant, but on a small device like this I would have though performance is much more important. My experience from my work is that XML generally is a great format, but flawed by the bloat it creates for large documents, and the signification overhead involved in parsing it.
I haven’t looked, but I’m sure Cocoa has an API to break a CSV line into its constituent components. I’d be interested in a comparison and in fact when i get around to actually doing some work on the iPhone i will probably do one for my own interest.
Regards,
Greg
Gregorski on September 27th, 2009
Just to clarify, i mean’t transform it BEFORE adding it to your XCode projcet.
mike on September 27th, 2009
Hi Greg
Your right, reducing the XML down to maybe a comma delimited file would be very quick although as you say, not as easy to read.
The reason I’ve stuck with XML is that with TBXML I’m now able to parse the XML so quickly I’m not seeing the need to move to a flat file. Also, tools such as Tiled allow you to add properties to things like maps, layers and object groups. Whilst handling this is possible in a pre-process stage before it hits the project, it is more work.
I completely agree about the bloat that XML can bring with it, but now that I can get Tiled to gzip its contents I end up with a very very small file that I can parse quickly and still benefit from being able to traverse the XML document when parsing in complex structure such as object groups etc.
I was definitely moving toward some kind of pre-processed file when I had load times of 20 seconds. With 600ms its quick enough for me not to worry.
If you do any tests between the two I would be really interested to see the results :o)
Mike
Gregorski on September 27th, 2009
I’ll need to find some time first to actual learn a few bits. I’m getting somewhere slowly with the help from your tutorials, but work travel commitments mean I am suffering from time deprivation. I’m going to start carrying my Macbook with me on my flights, but the thought of lugging 2 laptops through LHR isn’t a nice one :), and BA aren’t massively generous with their onboard workspace :(
Thanks for the help though.
By the way, is that Czech Granny for real ?
mike on September 27th, 2009
Say no more Greg, I completely understand where you are coming from. I travel a lot through LHR and all sorts of airlines and it is a nightmare.
I’ve cut down a little in that I’ve started using my Macbook for work as well, so I end up just carrying one laptop around. Workspace is still an issue though.
I’m off to Aus on 1st October for two weeks, then Toronto when I get back for a week and then the Nordics, I’m basically in planes and hotels for the whole of October, so I really do know how you feel.
As for the Granny I’m not sure. There has been a lot of speculation about it. I have my doubts, but stranger things have happened :o)
Mike
anon_anon on September 27th, 2009
How about vtd-xml? You may want to look at that as well? http://vtd-xml.sf.net
John on September 28th, 2009
Yeah I think the Granny could be a very clever PR stunt! :)




Library: TBXML at Under The Bridge on September 27th, 2009
[...] Well, that suits a good number of applications. As discussed on 71^2 here: [...]