如何使用VTD-XML解析器删除特定节点 [英] How to remove a specific node using VTD-XML parser

查看:209
本文介绍了如何使用VTD-XML解析器删除特定节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用VTD-XML解析器执行以下操作.

With the VTD-XML parser how do I do below.

<root>
     <A>
      <B>
        <c>1<c/>
        <d>2<d/>
        <e>3<e/>
      </B>
      <B>
        <c>1<c/>
        <d>2<d/>
        <e>3<e/>
      </B>
     </A>
 </root>

在上述xml中,如何仅删除具有标签名称的节点?

In the above xml how do I remove only nodes has tag name ?

所以我的最终成绩应该是

So my final out put should be

<root>
     <A>
     </A>
</root>

推荐答案

这是删除A的所有子节点的代码,关键是VTDNav的getContentFragment().

This is the code that removes all child nodes of A, the key is VTDNav's getContentFragment().

import com.ximpleware.*;

public class removeNode {

    public  static void main(String s[]) throws Exception{
        VTDGen vg = new VTDGen();
        boolean b = vg.parseFile("input.xml", false);
        if (b==false)
            return;
        VTDNav vn = vg.getNav();
        XMLModifier xm = new XMLModifier(vn);
        vn.toElement(VTDNav.FC); // get to A node
        long l = vn.getContentFragment();
        xm.remove(l);
        xm.output("output.xml");
    }
}

这篇关于如何使用VTD-XML解析器删除特定节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆