October 14, 2010 0

Parsing Delimited String from XMLNode on iOS using GDataXMLNode

By admin in Uncategorized

Often when you work with XML, you need to put a bunch of values into a node, maybe positioning information for example.
The best way to do that is to create a “Delimited String”, that is “ABC|123|XYZ|987″, is delimited by the | character.

Here’s how you get that back in iOS into an array, that you can then loop through and make use of:

Btw I’m using GDataXML, which is googles Objective-C xml reading/writing library. Needless to say it’s very good, and very fast.

Ok, so let’s turn this into an array:

<pos>297.00,30.00</pos>
// Broken into multiple lines to fit, it's a long one!
NSArray *myPositionList = [[[[[xmltree elementsForName:@"pos" ] objectAtIndex:0] stringValue]
     stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] 
           componentsSeparatedByString:@","];

Tags:

Leave a Reply

Powered by WP Hashcash

Spam protection by WP Captcha-Free