YOURLS を使用してカスタム URL 短縮サービスを作成しようとしています。YOURLS で組み込み API を使用すると、これが XML ドキュメントとしてクロムに表示されます。
<result>
<url>
<keyword>2</keyword>
<url>http://www.bing.com</url>
<title>http://www.bing.com</title>
<date>2013-06-08 19:24:28</date>
<ip>127.0.0.1</ip>
</url>
<status>success</status>
<message>http://www.bing.com added to database</message>
<title>http://www.bing.com</title>
<shorturl>http://127.0.0.1/2</shorturl>
<statusCode>200</statusCode>
</result>
「shorturl」にあるものだけが欲しい
ただし、日食でエラーが発生します
URL url=null;
try {
url = new URL("http://localhost/yourls/yourls-api.php?username=username&password=password&action=shorturl&url="+"http://google.ca");
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openConnection().getInputStream()));
String s = null;
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = (Document) db.parse((url).openStream());
XPath xpath = XPathFactory.newInstance().newXPath();
XPathExpression expr = (XPathExpression) xpath.compile("shorturl");
Object exprResult = expr.evaluate(doc, XPathConstants.NODESET);
NodeList nodeList = (NodeList) exprResult;
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
で
Object exprResult = expr.evaluate(doc, XPathConstants.NODESET);
エラーは、「XPathExpressions 型のメソッド evaluate(Node, short, object) は引数 (Document, QName) には適用できません」と表示されます。
これを修正する方法を知っている人はいますか?