DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Jimmy has posted 14 posts at DZone. View Full User Profile

Extract XML Fragment Using Extended VTD-XML

  • submit to reddit
        // This example demonstrate how to use extended vtd-xml to extract content out
// of a huge xml document. Notie that the parsing is set to memory mapped mode
// so that the processed file can exceed the size of physical memory.
// unlike standard VTD-XML, getElementFragment() of VTDNavHuge returns a array
// of longs, otherwise, null will be returned.


import com.ximpleware.*;
import com.ximpleware.extended.*;

public class cut {
	public static void main(String s[]) throws Exception{
		VTDGenHuge vgh = new VTDGenHuge();
		if (vgh.parseFile("c:/xml/text1.xml",true,VTDGenHuge.MEM_MAPPED)){
			VTDNavHuge vnh = vgh.getNav();
			long[] la = vnh.getElementFragment();
			if (la!=null)
			vnh.getXML().writeToFileOutputStream(new FileOutputStream("c:/xml/text2.xml"), la[0], la[1]);