java.lang.IllegalArgumentException:没有实现指定模式语言的 SchemaFactory

2022-09-04 01:58:59

我遇到以下异常:

java.lang.IllegalArgumentException:没有实现以下模式语言的 SchemaFactory:http://www.w3.org/2001/XMLSchema-instance 可以在 main 的 javax..xml.validation.SchemaFactory.newInstance(SchemaFactory.java:204) 上加载。SchemaImport3.validateXMLSchema(SchemaImport3.java:74) at MAIN.SchemaImport3.main(SchemaImport3.java:62)

这是我的代码:

URL source;
source = new URL(schemaList.getDocumentBaseURI());
SchemaFactory factory = SchemaFactory.newInstance(
                         XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI);

答案 1

用:XMLConstants.W3C_XML_SCHEMA_NS_URI

SchemaFactory factory = SchemaFactory.newInstance( 
    XMLConstants.W3C_XML_SCHEMA_NS_URI 
);

URI“http://www.w3.org/2001/XMLSchema-instance”(的值)本身不是 XML 架构语言,而是 XML 架构的属性(或功能,或者其他机制,如果你愿意的话)。XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI

W3C XML 架构的正确名称是“http://www.w3.org/2001/XMLSchema”(的值)。XMLConstants.W3C_XML_SCHEMA_NS_URI


答案 2

推荐