我想从URL中获取值。请做一些帮助或提供一些有用的链接,我可以获得解决方案。请帮忙提前道谢。
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();
}发布于 2017-07-19 16:10:09
https://stackoverflow.com/questions/45184373
复制相似问题