开发者

XPath XML query

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 开发者_如何学Cnil.


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

...

<xsl:value-of select="/item/title"/>

...

If you were programmatically accessing that data in PHP it would be something like:

$doc = new DOMDocument;
$doc->loadXML("<item><title>My name is Kevin</title></item>");
$xpath = new DOMXPath($doc);
$query = "/item/title";
$entries = $xpath->query($query);
foreach ($entries as $entry) { print $entry->nodeValue; }


Use this XPath: /item/title/text()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜