NodeList值没有更新?

时间:2011-10-12 07:54:15

标签: java

此语句根本不会更新相关节点的值!你能告诉我为什么会这样,或者我在这里做错了吗?!?

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));
}

谢谢

1 个答案:

答案 0 :(得分:0)

请检查此链接:

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

您可以看到代码无效的原因。您的节点应该是'attribute'来获取/设置其值。可能在你的情况下list.item(i)引用了一个'元素'类型,这就是它不起作用的原因。你应该遍历(转到孩子),直到找到属性类型。

相关问题