我有一个这样的示例XML:
<rss version="2.0">
<channel>
<title></title>
<link></link>
<description></description>
<item>
<title></title>
<link></link>
<description></description>
<pubDate></pubDate>
<guid></guid>
</item>
等等……我的obj-c语法看起来像这样:
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
DDXMLDocument *ddDoc = [[DDXMLDocument alloc] initWithData:data options:0 error:&error];
NSArray *xmlItems = [ddDoc nodesForXPath:@"//item" error:&error]; // where ddDoc is your DDXMLDocument
NSMutableArray *returnArray = [[NSMutableArray alloc] initWithCapacity:[xmlItems count]];
for(DDXMLElement* itemElement in xmlItems)
{
ActiveActivity *activity = [[ActiveActivity alloc] init];
NSString *itemValueAsString = [[itemElement attributeForName:@"link"]stringValue];
[returnArray addObject:activity];
}
它没有回报,有人可以说我为什么吗?
最佳答案
问题在这一行:
NSString *itemValueAsString = [[itemElement attributeForName:@"link"]stringValue];
link
不是属性,而是元素。所以试试这个: NSString *itemValueAsString = [[[itemElement elementsForName:@"link"] lastObject] stringValue];
关于iphone - KissXML不返回字符串,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9274031/