【发布时间】:2011-12-24 03:32:39
【问题描述】:
我用XPath解析rss xml数据,数据是
<rss version="2.0">
<channel>
<title>
<![CDATA[sports news]]>
</title>
</channel>
</rss>
我想用xpath "/rss/channel/title/text()" 得到文本"sports news",但是结果不是我想要的,真正的结果是"\r\n",那么如何找到我想要的结果。
代码如下:
文档 doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(is); XPathFactory xpathFactory = XPathFactory.newInstance(); XPath xPath = xpathFactory.newXPath(); 节点 node = (Node) xPath.evaluate("/rss/channel/title/text()", doc,XPathConstants.NODE); 字符串标题 = node.getNodeValue();【问题讨论】: