带变量的Java Xpath
我有以下XML:带变量的Java Xpath,java,xpath,Java,Xpath,我有以下XML: <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/"> <channel rdf:about="http://www.web.com/news.rss"> <items> <rdf:Seq> <rdf:li resource="http://www.web.com/news1
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://purl.org/rss/1.0/">
<channel rdf:about="http://www.web.com/news.rss">
<items>
<rdf:Seq>
<rdf:li resource="http://www.web.com/news1" />
<rdf:li resource="http://www.web.com/news2" />
</rdf:Seq>
</items>
</channel>
<item rdf:about="http://www.web.com/news1">
<title>my title</title>
<link>http://www.web.com/news1.html</link>
<description> bla bla </description>
</item>
<item rdf:about="http://www.web.com/news2">
<title>My Title 2</title>
<link>http://www.web.com/news2.html</link>
<description> bla bla 2 </description>
</item>
</rdf:RDF>
下面是我尝试打印每个rdf:li的标题的代码
在我的循环中一切正常,NewsTitle变量给了我很好的结果
我的问题是我的xpath。Compile不好,我需要帮助知道如何调用我的xpath来查找每个新闻的标题,这些新闻将给出以下结果:
发件人:
标题:布拉布拉
发件人:
标题:bla bla 2
我不能用粗体字写这句话。标题:布拉布拉布拉
谢谢谢谢我终于找到了自己。 Xpath需要删除名称空间rdf: 鉴于此:
String NoTitre = xPath.compile("//item[@about='" + NouvelleTitre + "']/title").evaluate(doc);
可能重复的
String NoTitre = xPath.compile("//item[@about='" + NouvelleTitre + "']/title").evaluate(doc);