gpt4 book ai didi

Java VTD-XML 找不到符号错误。编译java时如何正确引用包?

转载 作者:行者123 更新时间:2023-11-30 02:56:41 25 4
gpt4 key购买 nike

我不是 Java 程序员,但需要编写 Java 程序来解析大型(400mb)xml 文件。我选择了 vtd-xml,但不知道如何正确引用该包。我不想使用 maven/gradle 因为我不经常用 Java 编程,只是真的需要引用这个包。我有:

import com.ximpleware.*;

在我的java文件的顶部。我将 vtd-xml 源代码保存在与 java 文件相同的目录中,因此目录结构如下所示:

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

我导出了类路径,以便

echo $CLASSPATH

返回

vtd_xml/vtd-xml_light-2-12.jar

但是当我去编译我的java文件时,

javac my_java.java

我收到以下(令人沮丧的)错误:

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

我做错了什么?这是我的源代码,以防有帮助:

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());
}
}
}
}

更新我的符号错误仍然看起来像:

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

最佳答案

您需要返回 vtd-xml 网站并下载 vtd-xml 的标准版本...来解释这一点:

实际上有 3 个 vtd-xml 版本:

--- 轻型解析器被剥离用于移动设备的准系统解析器--- 标准是最强大/功能最丰富和完整的标准--- 扩展版功能较少,但支持最大 256 GB 的文档

所以我认为您正在寻找的是标准版......

这是链接...

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

您的代码中有一个小错误

ap.evalXPathToNumber 返回一个 double,而不是节点集,因此您可以直接对返回结果进行赋值并使用它...而无需循环...

另一个建议,您可以打开 VTDGen 的 vg.setLCLevel(5) 这可能有助于提高 xpath 性能...

关于Java VTD-XML 找不到符号错误。编译java时如何正确引用包?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37059122/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com