[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"]){
        } 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…

Related Posts Plugin for WordPress, Blogger...

One thought on “[iOS] TBXML traversing complete

  1. ya_bhim

    -> is a pointer to nextSibling

    typedef struct _TBXMLElement {
    char * name;
    char * text;

    TBXMLAttribute * firstAttribute;

    struct _TBXMLElement * parentElement;

    struct _TBXMLElement * firstChild;
    struct _TBXMLElement * currentChild;

    struct _TBXMLElement * nextSibling;
    struct _TBXMLElement * previousSibling;

    } TBXMLElement;
    you should read some course of objective-c


Leave a Reply

Your email address will not be published. Required fields are marked *

8 − = seven

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>