我想从网址获取价值。请帮助或提供一些有用的链接,我可以得到解决方案。请提前帮助谢谢。
try {
URL url = new URL("http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml");
URLConnection conn = url.openConnection();
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(conn.getInputStream());
NodeList nodes = doc.getElementsByTagName("Cube");
Element element = (Element) nodes.item(0);
NodeList title = element.getElementsByTagName("Cube");
Element line = (Element) title.item(0);
Toast.makeText(this, "USD " + line.getTextContent().toString(), Toast.LENGTH_SHORT).show();
} catch (Exception e) {
e.printStackTrace();
}