Referencing a XSD schema within jar file(在 jar 文件中引用 XSD 架构)
问题描述
我有两个架构文件,一个是从另一个导入的.在 Eclipse 架构中执行代码时找到但从 jar 架构文件中执行代码时找不到
I have two schema files one is imported from the other. When executing the code in Eclipse schemas are found but when executing the code from jar schema files are not found
这里是代码
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
factory.setValidating(false);
SchemaFactory schemaFactory = SchemaFactory
.newInstance("http://www.w3.org/2001/XMLSchema");
try {
factory.setSchema(schemaFactory.newSchema(new Source[] {
new StreamSource(getClass().getResource("Liso.xsd")
.getFile()),
new StreamSource(getClass().getResource("LisoXml.xsd")
.getFile()) }));
this.saxParser = factory.newSAXParser();
} catch (SAXException se) {
System.out.println("SCHEMA : " + se.getMessage()); // problem in the XSD itself
}
这是我得到的错误
SCHEMA : schema_reference.4: Failed to read schema document 'file:/C:/Tools/lib/LisoTools.jar!/com/xerox/liso/xml/Liso.xsd', because 1) could not find the do
cument; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
谢谢
推荐答案
如果Liso.xsd
是在导入LisoXml.xsd
,那么定义即可>Liso.xsd
到模式工厂,如下所示.该 API 足够智能,可以加载导入/包含的架构.
If Liso.xsd
is importing LisoXml.xsd
, then it is just sufficient to define Liso.xsd
to the schema factory as shown below. The api is smart enough the load the imported/included schema(s).
SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema")
Schema compiledSchema = schemaFactory.newSchema(getClass().getClassLoader().getResource("Liso.xsd"))
我验证这在 1.5 和 1.6 上都有效.在 1.6 上,您可能会遇到 这个问题如果使用 DOM 就好了.
I verified this worked on both 1.5 and 1.6. On 1.6, you might hit in to this issue as well if using DOM.
这篇关于在 jar 文件中引用 XSD 架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 jar 文件中引用 XSD 架构
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01