Over a million developers have joined DZone.

How To Create And Loading Index For XML Document Using VTD-XML?

This example has two applications that respectively generate VTD+XML index for XML, and load VTD+XML index (thus bypass parsing).

The code below indexes the XML documents

import com.ximpleware.*;
import java.io.*;
public class createIndex {
      public static void main(String[] args) throws Exception{
                     VTDGen vg = new VTDGen();
                     if (args.length != 2)
                             throw new Exception("Invalid # of arguments");

                     String inputName = args[0];
                     String outputName = args[1];

                     if (vg.parseFile(inputName,true)){
                        vg.writeIndex(new FileOutputStream(outputName));

Below is the code for loading the index

import java.io.*;
import com.ximpleware.*;
public class loadIndex {
         public static void main(String[] args) throws IOException,IndexReadException {
                 VTDGen vg = new VTDGen();
                 VTDNav vn = vg.loadIndex(args[0]);
                // put the processing logic here 

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

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.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}