我有一个这样的示例 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/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |