我只能解析这个xml的第一个元素,但我想获得所有菜肴的内容 这是我的xml
<cuisines>
<cuisine>Asian</cuisine>
<cuisine>Nepalese</cuisine>
<cuisine>North Indian</cuisine>
<cuisine>Indian Vegetarian</cuisine>
<cuisine>Organic Cuisine</cuisine>
</cuisines>
这是解析的代码
if ( [elementName isEqualToString:@"cuisines"]) {
if ( [elementName isEqualToString:@"cuisine"] ) {
elementName=[[NSMutableString alloc] init];
keyInProgress = [elementName copy];
// This is a string we will append to as the text arrives
textInProgress = [[[NSMutableString alloc] init]autorelease];
return;
}
但它不起作用我想得到所有的价值
答案 0 :(得分:1)
您需要实现解析器方法以及以下NSXMLParserDelegate协议方法方法:
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
可在此处找到一个好的教程:Consuming a RESTful Service (bit.ly) in an iPhone Application