XML要素からデータを取得するために、XPathで動作する次のJavaコードがあります。表現がtitle
で初めて解明されたとき、それは正常に機能します。しかし、次回はcost
で、cost
の値を表示するたびに、「コストを得ることができませんでした」と表示されます。複数のXPath式を実行しようとしたときに何か不足していますか?XPathが正しく機能しない
XPathFactory factory = XPathFactory.newInstance();
XPath xpath = factory.newXPath();
XPathExpression exp;
InputSource inputSource = new InputSource(new StringReader(woot_xml));
title = "Could not get title";
cost = "Could not get cost";
try {
exp = xpath.compile("/rss/channel/item/title");
title = exp.evaluate(inputSource);
exp = xpath.compile("/rss/channel/item/pubDate");
cost = exp.evaluate(inputSource);
} catch (XPathExpressionException e) {
// Do nothing for now
}
これは私がオフつもりXML:http://www.woot.com/salerss.aspx
XMLはどのように見えますか? –
試着?:// rss/channel/item/title and // rss/channel/item/pubDate(double // start) – Steven
質問をXMLで更新しました。そして私は//を試しましたが、動作しません。 – Chiggins