3 回答
TA贡献1794条经验 获得超8个赞
ISSUCCESS 是一个元素而不是一个属性。
改成:
NodeList nodeList = doc.getElementsByTagName("QRYRESULT");
for (int i = 0; i < nodeList.getLength(); i++) {
Element value = (Element) nodeList.item(i);
String ISSUCCESS = value.getElementsByTagName("ISSUCCESS").item(0).getTextContent();
System.out.println("ISSUCCESS = " + ISSUCCESS);
}
TA贡献1868条经验 获得超4个赞
DocumentBuilderFactory dbf =DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(**myXML**));
Document doc = db.parse(is);
NodeList nodes = doc.getElementsByTagName("QRYRESULT");
Element qryresult = (Element) nodes.item(0);
Element success = (Element) qryresult.getElementsByTagName("ISSUCCESS").item(0);
String iSuccess=success.getFirstChild().getTextContent();
System.out.println("ISSUCCESS: " + iSuccess);
TA贡献1875条经验 获得超3个赞
试试这个。
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(contactsXMLstream);
doc.getDocumentElement().normalize();
NodeList nList = doc.getElementsByTagName("QRYRESULT");
entries=new MarketEntry[nList.getLength()];
for (int temp = 0; temp < nList.getLength(); temp++)
{
Node nNode = nList.item(temp);
if (nNode.getNodeType() == Node.ELEMENT_NODE)
{
Element eElement = (Element) nNode;
String vr= eElement.getElementsByTagName("ISSUCCESS").item(0).getTextContent();
}
}
添加回答
举报