TouchXML,获取节点objective-c的文本值
我查遍了整个网络,但就是不知道如何从 Objective-C 中的节点获取文本。我正在使用 TouchXML,并且正在获取我的节点列表。我想要来自节点的标题文本,但我得到了一个节点对象。我的代码是:
resultNodes = [xmlParser nodesForXPath:@"SearchResults/SearchResult" error:&err];
for (CXMLElement *resultElement in resultNodes) {
NSString *value = [resultElement elementsForName:@"Title"];
}
如果我将值记录到控制台,我得到:
<CXMLElement 0x3994b10 [0x39732a0] Title <Title HtmlEncoded="true">test question</Title>>
我想要文本,即测试问题
。我正在用头撞这里的砖墙。
I've looked all over the web but just can't figure out how to get the text from a node in Objective-C. I'm using TouchXML and I am getting my node list. I want the title text from a node, but instead I get a node object. My code is:
resultNodes = [xmlParser nodesForXPath:@"SearchResults/SearchResult" error:&err];
for (CXMLElement *resultElement in resultNodes) {
NSString *value = [resultElement elementsForName:@"Title"];
}
If I log the value to the console I get:
<CXMLElement 0x3994b10 [0x39732a0] Title <Title HtmlEncoded="true">test question</Title>>
I want the text, i.e test question
instead. I am banging my head against a brick wall here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于给定值“Title”的“resultElement”中应该至少有一个元素,因此您可以通过添加以下代码行来访问它:
Since there should atleast one element in "resultElement" for the given value"Title", you can probably access it by adding following line of code:
尝试:
Try: