Question

I'm using TBXML in my iphone application. I have an xml like the next one:

<detail>
    <title>My title</title>
    <subs>
       <sub>subCategory1</sub>
       <sub>subCategory2</sub>
       <sub>subCategory3</sub>
    </subs>
</detail>

I can successfully get the title and ONLY the first of subcategories. The code I'm using for getting the sub categories is the following:

NSMuttableArray *divs = [[NSMuttableArray] initWithCapacity:3];
TBXMLElement *subsElement = [TBXML childElementNamed:@"subs" parentElement:currentElement];
TBXMLElement *subElement = [TBXML childElementNamed:@"sub" parentElement:subsElement];
do {
    [divs addObject:[TBXML textForElement:subElement]];
    NSLog(@"%@ , %@", @"Got one subCategory " , divs.lastObject);
} while ((subsElement = subsElement->nextSibling));
Was it helpful?

Solution

It looks like you have a typo in your where statement. I believe you meant to use subElement instead of subsElement. So your code should be:

while ((subElement = subElement->nextSibling));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top