Index
Creation and Loading
(For more code samples,
visit Official VTD-XML Blog)
(Separate code-only
VTD-XML tutorials are available in
C,
C++,
Java
and
C#)
This example has two
applications that respectively generate
VTD+XML index for XML,
and load VTD+XML index (thus bypass parsing). Those application are pretty
short, and they are available here:
createIndex.java
loadIndex.java
Here is the code for creating
VTD+XML index. The recommended output suffix for the index is ".vxl" so the
index for "input.xml" is "input.vxl."
// createIndex creates a VTD+XML index
for an input XML document
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));
}
}
}
|
Here is the code for loading
the index.
// loadIndex.java loads a VTD+XML index
file into memory
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
}
}
|