NSXML Parser逐节点解析

时间:2013-03-27 07:39:55

标签: ios objective-c nsxml

我有这样的XML,

<?xml version="1.0" standalone="yes"?>
<user id="1" name=""><class id="1" name=""><subjects id="1" name=""><books id="1" name="">   
<chapters id="1" name="">
<pages id="0" name="" url="http://172.16.33.25/casa/admin/uploads/mathematic/Page001.html"/>
<pages id="1" name="" url="http://172.16.33.25/casa/admin/uploads/mathematic/Page002.html"/>
</chapters></books></subjects></class></user>

这里我需要数组中的url值,我正在使用NSXML Parser。我怎么解析这个。?

1 个答案:

答案 0 :(得分:0)

尝试

-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{         
    if([elementName isEqualToString:@"pages"])
    {
        NSString *urlValue=[attributeDict valueForKey:@"url"];
        [arr addObject:urlValue];
    }
}