1

I'm not a Java programmer, but need to write a Java program to parse a large (400mb) xml file. I've chosen vtd-xml, but don't know how to properly reference the package. I don't want to use maven/gradle because I don't often program in Java, and just really need to reference this one package. I have:

import com.ximpleware.*;

at the top of my java file. I have the vtd-xml source code saved in the same directory as my java file, so that the directory structure looks like:

my_java.java
vtd_xml/com
vtd_xml/example
vtd_xml/install.txt  
vtd_xml/Readme.txt   
vtd_xml/ximpleware_2.12-java-light.zip
vtd_xml/vtd-xml_light-2-12.jar

I exported the classpath so that

echo $CLASSPATH

returns

vtd_xml/vtd-xml_light-2-12.jar

but when I go to compile my java file,

javac my_java.java

I get the following (frustrating) errors:

zephyr_4.java:18: error: cannot find symbol
            XMLModifier xm = new XMLModifier(vn);
            ^
  symbol:   class XMLModifier
  location: class zephyr_4
zephyr_4.java:18: error: cannot find symbol
                XMLModifier xm = new XMLModifier(vn);
                                 ^
  symbol:   class XMLModifier
  location: class zephyr_4
zephyr_4.java:23: error: cannot find symbol
            ap.selectXPath(query);
              ^
  symbol:   method selectXPath(String)
  location: variable ap of type AutoPilot
zephyr_4.java:28: error: cannot find symbol
                while((i=ap.evalXPathToNumber())!=-1){
                       ^
  symbol:   method evalXPathToNumber()
  location: variable ap of type AutoPilot
zephyr_4.java:29: error: cannot find symbol
                    System.out.println(vn.toNormalizedPathString()); 
                                     ^
  symbol:   method toNormalizedPathString()
  location: variable vn of type VTDNav

What am I doing wrong? Here is my source code in case that's helpful:

import java.io.*; 
import com.ximpleware.*;
import java.util.*;

public class my_java {
      public static void main(String argv[]) throws NavException, IOException{
            // open a file and read the content into a byte array
            VTDGen vg = new VTDGen();
            if (vg.parseFile("pubmed_result.xml", true)){
                VTDNav vn = vg.getNav();
                AutoPilot ap = new AutoPilot(vn);
                XMLModifier xm = new XMLModifier(vn);
                String query = "count(//PubmedArticleSet/PubmedArticle"
                   + "/MedlineCitation/Article"
                   + "/AuthorList/Author[contains(LastName,\"Sangani\") and "
                   + "contains(ForeName, \"Rahul G\")])";
                ap.selectXPath(query);
                ap.bind(vn);


                int i = -1;
                while((i=ap.evalXPathToNumber())!=-1){
                    System.out.println(vn.toNormalizedPathString()); 
                }
            }
      }
}

UPDATE My symbol error still looks like:

zephyr_4.java:8: error: cannot find symbol
import com.ximpleware.VTDGen;
                 ^
  symbol:   class VTDGen
  location: package com.ximpleware
zephyr_4.java:10: error: cannot find symbol
import com.ximpleware.AutoPilot;
                 ^
  symbol:   class AutoPilot
  location: package com.ximpleware
 zephyr_4.java:11: error: cannot find symbol
import com.ximpleware.XMLModifier;
                 ^
  symbol:   class XMLModifier
  location: package com.ximpleware
zephyr_4.java:16: error: cannot find symbol
      public static void main(String argv[]) throws NavException,      IOException{
                                                ^
  symbol:   class NavException
  location: class zephyr_4
zephyr_4.java:18: error: cannot find symbol
            VTDGen vg = new VTDGen();
            ^
  symbol:   class VTDGen
  location: class zephyr_4
zephyr_4.java:18: error: cannot find symbol
            VTDGen vg = new VTDGen();
                        ^
  symbol:   class VTDGen
  location: class zephyr_4
zephyr_4.java:21: error: cannot find symbol
                AutoPilot ap = new AutoPilot(vn);
                ^
  symbol:   class AutoPilot
  location: class zephyr_4
zephyr_4.java:21: error: cannot find symbol
                AutoPilot ap = new AutoPilot(vn);
                               ^
  symbol:   class AutoPilot
  location: class zephyr_4
zephyr_4.java:22: error: cannot find symbol
                XMLModifier xm = new XMLModifier(vn);
                ^
  symbol:   class XMLModifier
  location: class zephyr_4
zephyr_4.java:22: error: cannot find symbol
                XMLModifier xm = new XMLModifier(vn);
                                     ^
  symbol:   class XMLModifier
  location: class zephyr_4
10 errors
Michael Pinkard
  • 205
  • 2
  • 10

1 Answers1

2

You need to go back to vtd-xml web site and download the standard edition of vtd-xml... to explain this:

There are actually 3 vtd-xml editions:

--- The light one is stripped down barebone parser intended for mobile devices --- standard is the most powerful/ feature rich and complete one --- extended edition has less feature but supports document up to 256 gb

So what you are looking for is standard edition I think...

Here is the link...

https://sourceforge.net/projects/vtd-xml/files/vtd-xml/ximpleware_2.12/VTD-XML%20Standard%20Edition/ximpleware-2.12-java.zip/download

There is a slight error in your code

ap.evalXPathToNumber returns a double, not a node set, so you can assign the returned result directly and use it... while loop unnecessary...

Another suggestion, you could turn on VTDGen's vg.setLCLevel(5) which may help improve xpath performance...

vtd-xml-author
  • 3,319
  • 4
  • 22
  • 30