1

[iOS] TBXML traversing complete

I’ve started playing around with TBXML for an iOS application I am creating and it’s working very well, but online I haven’t seen any example code which detects when the traversing do while loop has actually completed. This would be useful in knowing that a data container is fully populated with parsed XML data & you could then properly call a method with that data container. (ie. [self callSomeMethod:dataContainer]).

I still have NO idea: “element -> firstChild” … what is that “->” actually mean? I’ve tried Googling but haven’t found anything yet. I am not new to Objective-C but I’m still learning it. If anyone knows what that “->” means there, I’d appreciate it.

Anyway, you can do something like this to detect when all traversing is complete:

- (void)traverseElement:(TBXMLElement *)element {
    do {
        if(element -> firstChild)
            [self traverseElement:element -> firstChild];
        if([[TBXML elementName:element] isEqualToString("foo"]){
            //stuff
        } else if(!element -> parentElement){
            NSLog(@"Done traversing XML");
        }
    } while ((element = element -> nextSibling));
}

Handy to know, in fact I’m surprised that I haven’t seen that online anywhere in any of the examples I’ve found. I would think knowing when that do-while is done would be of significant importance. If there is a better way to handle this, please use the comments. And also if you know about that “->” stuff I’d love to know about that too…

Popularity: 1%

0

Soundrop user? Coding playlist is up.

screenshotI’ve been running Spotify for a while now and I almost never even think about iTunes anymore. I own a ton of music there, which just filters into Spotify.

Anyway, I have a pretty epic Coding playlist that I listen to during the day. Want to participate? Vote on tracks, add tracks, leave messages, etc?

Your link is below. I am using Soundrop within the Spotify beta.

Link: Eric E. Dolecki Coding.

Popularity: 1%