Over a million developers have joined DZone.

Extract XML Fragment Using Extended VTD-XML

DZone's Guide to

Extract XML Fragment Using Extended VTD-XML

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

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}