1

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));
Panos
  • 7,227
  • 13
  • 60
  • 95
  • This doesn't answer your question directly, but I would choose [`RaptureXML`](https://github.com/ZaBlanc/RaptureXML) over TBXML in a heartbeat for XML parsing on iOS. I'd take a look at it; parsing what you're trying to parse would be incredibly easy. – sudo rm -rf May 09 '12 at 01:02

1 Answers1

2

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));
jonkroll
  • 15,682
  • 4
  • 50
  • 43
  • It was not a typo. It was the parent element type . But actually this is what it should have been. – Panos May 09 '12 at 08:36