Iphone 如何使用NSXMLParser访问完全相同的元素

Iphone 如何使用NSXMLParser访问完全相同的元素,iphone,xml,nsxmlparser,Iphone,Xml,Nsxmlparser,我需要解析一个XML文件。这是(为了清晰起见,请将其剥离): 雅虎!某地天气 问题是,正如您所看到的,有两个yweather:forecast元素,它们都没有任何可以用来区分这两个元素的静态文本。有什么想法吗 啊,结果很简单。以下是我所做的: if([elementName isEqualToString:@"yweather:forecast"]) { if (counter == 0) { TodaysHigh = [attributeDict obje

我需要解析一个XML文件。这是(为了清晰起见,请将其剥离):


雅虎!某地天气

问题是,正如您所看到的,有两个
yweather:forecast
元素,它们都没有任何可以用来区分这两个元素的静态文本。有什么想法吗

啊,结果很简单。以下是我所做的:

if([elementName isEqualToString:@"yweather:forecast"]) {
    if (counter == 0) {
        TodaysHigh      = [attributeDict objectForKey:@"high"];
        TodaysLow       = [attributeDict objectForKey:@"low"];
        counter ++; //where counter is an instance variable
    }

    if (counter == 1) {
        TomorrowsLow            = [attributeDict objectForKey:@"low"];
        TomorrowsHigh           = [attributeDict objectForKey:@"high"];
        TomorrowsCondition      = [attributeDict objectForKey:@"text"];
        TomorrowsConditionCode  = [attributeDict objectForKey:@"code"];
    }
}

小菜一碟,对吧?:)

我知道周围也有类似的问题,但在各个方面略有不同。你能告诉我们问题是什么吗?如果我要解析它,我可能会有一个表示“forecast”节点的类,并简单地构建它们的数组。为了帮助你,我们需要知道什么不起作用。@Mystik:我只是不知道如何处理两个相同的元素。我需要获取每个
yweather:forecast
中的元素,并将它们添加到单独的数组中。我认为您应该将forecast的概念打包到“forecast”对象中。这样就不必知道柜台上每个插槽都有什么了。然后,您可以在不修改代码的情况下处理可变天数。
if([elementName isEqualToString:@"yweather:forecast"]) {
    if (counter == 0) {
        TodaysHigh      = [attributeDict objectForKey:@"high"];
        TodaysLow       = [attributeDict objectForKey:@"low"];
        counter ++; //where counter is an instance variable
    }

    if (counter == 1) {
        TomorrowsLow            = [attributeDict objectForKey:@"low"];
        TomorrowsHigh           = [attributeDict objectForKey:@"high"];
        TomorrowsCondition      = [attributeDict objectForKey:@"text"];
        TomorrowsConditionCode  = [attributeDict objectForKey:@"code"];
    }
}