iphone TBXML xml解析

时间:2012-05-09 00:57:08

标签: iphone ios xml parsing tbxml

我在我的iphone应用程序中使用TBXML。我有一个类似下一个的xml:

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

我可以成功获得标题,而且只能获得第一个子类别。我用来获取子类别的代码如下:

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));

1 个答案:

答案 0 :(得分:2)

您的where声明中似乎有拼写错误。我相信您打算使用subElement代替subsElement。所以你的代码应该是:

while ((subElement = subElement->nextSibling));
相关问题