简体   繁体   中英

NodeList value does not get updated?

This statement simply would not update the value of the node in question! Could you please tell me why this is the case or if I'm doing something wrong here?!?

for (int i = 0; i < list.getLength(); i++) {
  temp = list.item(i).toString();
  System.out.println(temp.substring(temp.indexOf("\"")+1, temp.lastIndexOf("\"")));
  list.item(i).setNodeValue(temp.substring(temp.indexOf("\"")+1, temp.lastIndexOf("\"")));
  System.out.println(list.item(i));
}

Thanks

Please check this link:

Node Javadoc http://download.oracle.com/javase/1.4.2/docs/api/org/w3c/dom/Node.html#setNodeValue(java.lang.String )

You can see why your code doesn't work. Your node should be 'attribute' to get/set its value. Probably in your case list.item(i) refers to an 'element' type and that's why it doesn't work. You should traverse (go to child) until you find an attribute type.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM