当我从xml节点获取数据时,我得到空数据

时间:2018-05-25 13:50:30

标签: java web-services

我正在接收' 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();
      }
   }
}

0 个答案:

没有答案