How to remove a specific node using VTD-XML parser

主宰稳场 提交于 2019-12-01 12:48:52

问题


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>

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

So my final out put should be

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

回答1:


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


来源:https://stackoverflow.com/questions/22060447/how-to-remove-a-specific-node-using-vtd-xml-parser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!