XPath XML 查询
我在使用 xml 查询时遇到问题。下面是xml文档。我需要做的就是显示 cdata 部分内的文本。我写了这个查询:/item/title/text()
,但它崩溃了并且不起作用。
<title>
<![CDATA[Envious at Envie! 50% off anything you want, anytime you want!]]>
</title>
我正在为 iphone xcode 使用 hpple 库。这是我的代码:
NSData *urlData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:[@"http://www.twangoo.com/userfiles/rss/rss_hong-kong.xml" stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
TFHpple *xpathParser = [[TFHpple alloc] initWithHTMLData:urlData];
NSArray *title = [xpathParser search:@"//rss/channel/item[1]/title/text()"];
TFHppleElement *element2 = [title objectAtIndex:0];
NSString *titleString = [element2 content];
NSLog(@"@%", titleString)
它返回零。
I have trouble working with xml query. Below is the xml document. All I need to do is to display the text inside the cdata section. I wrote this query: /item/title/text()
, but it crashed and doesn't work.
<title>
<![CDATA[Envious at Envie! 50% off anything you want, anytime you want!]]>
</title>
I am using hpple library for iphone xcode. Here is my code:
NSData *urlData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:[@"http://www.twangoo.com/userfiles/rss/rss_hong-kong.xml" stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
TFHpple *xpathParser = [[TFHpple alloc] initWithHTMLData:urlData];
NSArray *title = [xpathParser search:@"//rss/channel/item[1]/title/text()"];
TFHppleElement *element2 = [title objectAtIndex:0];
NSString *titleString = [element2 content];
NSLog(@"@%", titleString)
It returns nil.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您可以提供更多有关您的环境、语言、正在使用的库以及生成的实际错误消息的信息,那将会有很大帮助。
但是,我认为 xsl 样式表中的有效 xslt 语句将是
……
如果您以编程方式在 PHP 中访问该数据,
它将类似于:
If you could provide a bit more information as to your environment, language, which libraries use are using and the actual error message produced that would help a lot.
However, I think a valid xslt statement in an xsl stylesheet would be
...
...
If you were programmatically accessing that data in PHP it would be something like:
使用此 XPath:
/item/title/text()
Use this XPath:
/item/title/text()