我正在学校里解析 xml,我正在使用 Twitter 的 API 来处理。我正在尝试获取发布推文的日期,但遇到了一个问题:有两个同名元素在 xml.xml 中保存不同的值。但是,一个比另一个嵌套得更远,因此从逻辑上讲,我想检查嵌套的那个。我该怎么做呢?
现在一切都在完美运行。我只想为我的项目添加更多内容。
这是我正在调用的 didEndElement 方法的示例。
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI: (NSString *)namespaceURI qualifiedName:(NSString *)qName
{
//Creates an instance of the singleton to grab the array stored there
DataArraySingleton *singleton = [DataArraySingleton sharedArray];
//easy access to array
NSMutableArray *array = singleton.theArray;
//If the element ends with text
if ([elementName isEqualToString:@"text"])
{
//Sets the value/key pair for text
[tweets setValue:currentXMLValue forKey:elementName];
}
//Same as above
if ([elementName isEqualToString:@"screen_name"])
{
[tweets setValue:currentXMLValue forKey:elementName];
}
//Same as above
if ([elementName isEqualToString:@"profile_image_url"])
{
[tweets setValue:currentXMLValue forKey:elementName];
}
//If the element ends with status
if ([elementName isEqualToString:@"status"])
{
//Adds the objects collected above to the array
[array addObject:tweets];
//Resets the object TweetInformation to be called again above
tweets = nil;
}
//Resets xml value
currentXMLValue = nil;
}
多谢你们