问题
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