我的编码如下:
try{
address = "http://isbndb.com//api/books.xml?
access_key=CKEHIG4D&index1=isbn&value1=" +barcode;
URL url = new URL(address);
URLConnection conn = url.openConnection();
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(conn.getInputStream());
NodeList nodes = doc.getElementsByTagName("BookData");
for (int i = 0; i < nodes.getLength(); i++) {
Element element = (Element) nodes.item(i);
NodeList title = element.getElementsByTagName("LongTitle");
Element line = (Element) title.item(0);
titleList.add(line.getTextContent());
}
}
catch (Exception e) {
e.printStackTrace();
}
和XML格式是
http://isbndb.com//api/books.xml?access_key=CKEHIG4D&index1=isbn&value1=1593270615
错误是行 - &gt; NodeList title = element.getElementsByTagName(“LongTitle”);
其实这有什么问题?
答案 0 :(得分:3)
确保导入正确的元素类(org.w3c.dom.Element)。
答案 1 :(得分:0)
更改“LongTitle” - &gt; “TitleLong”
in
NodeList title = element.getElementsByTagName("LongTitle");