本文介紹了如何使用 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 中,如何僅刪除具有標簽名稱 <B>
的節點?
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>
推薦答案
這是刪除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 解析器刪除特定節點的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!