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

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

11.29.2009
| 4558 views |
  • submit to reddit
        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 
        }
}