我有一个字符串 XML。我需要从 Java 中的 XML获取项目ISSUCCESS值。但项目值返回空值。这是我的 XML 代码。
XML
<QRYRESULT><ISSUCCESS>N</ISSUCCESS><REASON>E002</REASON><WARNING>1. Transaction date Should be current date.11-SEP-18 E </WARNING></QRYRESULT>
我已经编写了以下代码来获取ISSUCCESS项目值。
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(**myXML**));
Document doc = db.parse(is);
NodeList nodeList = doc.getElementsByTagName("QRYRESULT");
for (int i = 0; i < nodeList.getLength(); i++) {
Element value = (Element) nodeList.item(i);
String ISSUCCESS = value.getAttribute("ISSUCCESS");
System.out.println("ISSUCCESS = " + ISSUCCESS);
}
幕布斯7119047
MYYA
翻过高山走不出你
相关分类