gpt4 book ai didi

Java eclipse 错误 - 此行有多个标记 - URL 和 SAXException 无法解析为类型

转载 作者:行者123 更新时间:2023-11-29 10:14:40 25 4
gpt4 key购买 nike

我正在编写一个 Java 代码来根据 XSD 文件验证 XML。Eclipse 在以下代码中显示 2 个错误。

Multiple Markers at this line -

URL cannot be resolved to a type

SAXException cannot be resolved to a type

import javax.xml.XMLConstants;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.*;

public class xml_validator_class {

public static void main(String argv[]) {
URL schemaFile = new URL("xsdfile.xsd");
Source xmlFile = new StreamSource(new File("xmlfile.xml"));
SchemaFactory schemaFactory = SchemaFactory
.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(schemaFile);
Validator validator = schema.newValidator();
try {
validator.validate(xmlFile);
System.out.println(xmlFile.getSystemId() + " is valid");
} catch (SAXException e) {
System.out.println(xmlFile.getSystemId() + " is NOT valid");
System.out.println("Reason: " + e.getLocalizedMessage());
}


}

}

请引用this link对于以下程序:

最佳答案

导入缺失的类,使不合格的类型可以在程序中使用

import java.net.URL;
import org.xml.sax.SAXException;

关于Java eclipse 错误 - 此行有多个标记 - URL 和 SAXException 无法解析为类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20997592/

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