2

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 <B> ?

So my final out put should be

<root>
     <A>
     </A>
</root>
Stephan
  • 41,764
  • 65
  • 238
  • 329
user2771655
  • 1,052
  • 3
  • 20
  • 38

1 Answers1

0

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-author
  • 3,319
  • 4
  • 22
  • 30