简体   繁体   English

如何在iPhone上使用NSXML解析器获取所有值

[英]how to get all values using NSXML parser on iphone

i can only parse 1st element of this xml but i want to get all the content of cuisine this is my xml 我只能解析此xml的第一个元素,但我想获取所有美食的内容,这是我的xml

<cuisines>
<cuisine>Asian</cuisine>
<cuisine>Nepalese</cuisine>
<cuisine>North Indian</cuisine>
<cuisine>Indian Vegetarian</cuisine>
<cuisine>Organic Cuisine</cuisine>
</cuisines>

and this is the code to parse 这是要解析的代码

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

but its not working i want to get all the value 但它不起作用我想获得所有价值

you need to implement the parser method as well as the following NSXMLParserDelegate protocol methods methods: 您需要实现解析器方法以及以下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

A good tutorial can be found here: Consuming a RESTful Service (bit.ly) in an iPhone Application 可以在这里找到一个很好的教程: 在iPhone应用程序中使用RESTful服务(bit.ly)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM