如果在iphone编程中节点不是连续的,如何使用NSXMLParser?

时间:2011-09-08 11:25:04

标签: iphone nsxmlparser

我有以下链接,从以下链接返回XML

    http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=24.827774,67.034367    //This is URLString link

     NSXMLParser *xmlParser=[[NSXMLParser alloc] initWithContentsOfURL:[NSURL URLWithString:
                                                             [NSString stringWithFormat:@"%@",URLString]]]; 
    [xmlParser setDelegate:self];
    [xmlParser parse];



 - (void)parser:(NSXMLParser *)parser 
               didStartElement:(NSString *)elementName 
               namespaceURI:(NSString *)namespaceURI 
               qualifiedName:(NSString *)qualifiedName 
           attributes:(NSDictionary *)attributeDict {



 - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {

 - (void)parser:(NSXMLParser *)parser 
               didEndElement:(NSString *)elementName
               namespaceURI:(NSString *)namespaceURI 
               qualifiedName:(NSString *)qName {

我只想保存“city”“weather”“temp_f”和“temp_c”的值,以便在标签上显示;

我总是对NSXMLParser解析感到困惑,如果有人会用好词来定义,我会很感激,这样我才能正确理解NSXMLParser

先谢谢你

1 个答案:

答案 0 :(得分:1)

didEndElement委托方法中检查elementName

If(elemenentName isEqualtoString:@"city"])
// Save the element which is currently holding the value from the `foundCharacters` delegate method into your variable.

您可以对所需的其他值执行相同的操作。