我收到以下异常:
java.lang.IllegalArgumentException: No SchemaFactory that implements the schema language specified by: http://www.w3.org/2001/XMLSchema-instance could be loaded at javax.xml.validation.SchemaFactory.newInstance(SchemaFactory.java:204) at MAIN.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);
最佳答案
使用 XMLConstants.W3C_XML_SCHEMA_NS_URI
:
SchemaFactory factory = SchemaFactory.newInstance(
XMLConstants.W3C_XML_SCHEMA_NS_URI
);
URI“http://www.w3.org/2001/XMLSchema-instance”(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI
的值)本身不是一种 XML 模式语言,而是XML 架构。
W3C XML Schema 的正确名称是“http://www.w3.org/2001/XMLSchema”(XMLConstants.W3C_XML_SCHEMA_NS_URI
的值)。
关于java.lang.IllegalArgumentException : No SchemaFactory that implements the schema language specified 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22528848/