编程中国 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛  
 
全能 ASP / PHP / ASP.NET 主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付学习型 ASP/PHP/ASP.NET 主机 30元/年
发新话题
打印

xml的节点删除问题

xml的节点删除问题

<?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>节点没有删除掉.请高手指点,在线急等......

TOP

我觉得是删除方法有问题...
我的地盘我做主!

TOP

没人回...
我的地盘我做主!

TOP

发新话题