Over a million developers have joined DZone.

Extract XML Fragment Using Extended VTD-XML

·
// 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 java.io.FileOutputStream;

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();
			vnh.toElement(VTDNavHuge.FC);
			long[] la = vnh.getElementFragment();
			if (la!=null)
			vnh.getXML().writeToFileOutputStream(new FileOutputStream("c:/xml/text2.xml"), la[0], la[1]);
			
		}
	}
}
Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}