本文介绍了KissXML不返回字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个这样的XML示例:
I have an example XML like this:
<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语法看起来像这样:
and so on… And my obj-c syntax is looking like this:
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];
}
它没有任何价值,有人可以说我为什么吗?
It's returning no value, can anyone say me why?
推荐答案
问题出在这一行:
NSString *itemValueAsString = [[itemElement attributeForName:@"link"]stringValue];
link
不是属性,而是元素.所以试试这个:
link
is not an attribute, but rather an element. So try this:
NSString *itemValueAsString = [[[itemElement elementsForName:@"link"] lastObject] stringValue];
这篇关于KissXML不返回字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!