注册 登录
编程论坛 Ruby论坛

xml的节点删除问题

dingpin 发布于 2008-02-21 22:42, 6419 次点击
<?xml version="1.0" encoding="UTF-8"?>
<library>
     <book>
        <id>b001</id>
        <title>我是一个兵</title>
        <author>大兵</author>
     </book>
     <book>
    <id>007</id>
    <title>bookname</title>
    <author>ding</author>
     </book>
     <book>
    <id>007</id>
    <title>bookname</title>
    <author>ding</author>
     </book>
     <book>
    <id>007</id>
    <title>bookname</title>
    <author>ding</author>
     </book>
</library>

我想在JBuilder中删除<author>节点,我写了这个方法
 public void Delete(Document doc,String tagname){

    NodeList node=doc.getElementsByTagName(tagname);

    for(int i=0; i<node.getLength(); i++){
      node.item(i).getParentNode().removeChild(node.item(i));
    }
  }然后在主函数中调用,运行的时候弹出这样一个错Fatal exception occurred. Program will exit.
报这样的错误
java.lang.NullPointerException

    at AddBook.Delete(AddBook.java:91)

    at AddBook.main(AddBook.java:113)

Exception in thread "main"

xml文件中的<author>节点没有删除掉.请高手指点,在线急等......
2 回复
#2
dingpin2008-02-21 22:43
我觉得是删除方法有问题...
#3
dingpin2008-02-22 14:03
没人回...
1