我正在接收' null'我尝试从XML节点读取值时的值。
结构示例:
<document>
<user>ss</user>
<password >ssss</password >
</document>
结果:o / p [user:null] [密码:null]
这是我的代码:
public class stres() {
public static void main(String[] args) throws SQLException, ParserConfigurationException, SAXException, IOException {
try {
String resulturl ="my url";
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(resulturl);
NodeList documentt = doc.getElementsByTagName("document");
for (int i = 0; i < documentt.getLength(); i++) {
Element data = (Element) documentt.item(0);
Node user = data.getElementsByTagName("user").item(0);
Node password = data.getElementsByTagName("password").item(0);
}
}
catch(Exception e) {
e.printStackTrace();
}
}
}