XML 架构参考
我有两个 XML 模式。第一个 (A.xsd
) 位于库 jar 文件 (mylib.jar
) 中,第二个 (B.xsd
) 位于我的项目。
我想将 A.xsd
导入 B.xsd
并通过 Jaxb2Marshaller
嵌入式验证器验证传入的 XML。
但是我无法使其正常工作:似乎 Jaxb2Marshaller
的内部 XML 验证器不理解对 jar 文件中文件的引用(我只想写一些类似
)。
如何修复它?如何从项目架构中引用库架构?
I have two XML Schemas. First (A.xsd
) is located in a library jar file (mylib.jar
) and the second one (B.xsd
) is in my project.
I want to import A.xsd
into the B.xsd
and validate incoming XML via Jaxb2Marshaller
embedded validator.
However I'm unable to make it work properly: it seems that inner XML validator of Jaxb2Marshaller
does not understand references to files in jar-files (I just want to write something like <xs:import namespace="http://my/schema.xsd" schemaLocation="classpath:schema.xsd">
).
How it could be fixed? How could library schema be referenced from a project schema?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
查看我对上一个问题的回答,了解如何使用 ResourceResolver 来解决此问题:
您的 LSResourceResolver 实现将处理从类路径加载模式并将其转换为适当的结果。
Check out my answer to a previous question on how a ResourceResolver can be used to solve this problem:
Your implementation of LSResourceResolver will handle loading the schema from the classpath and converting it to the appropriate result.
您将需要配置自己的解析器。 jaxb 中的任何内容都不会使用 classpath:。
有一个 JAXB 示例展示了这类事情。
You will need to configure your own resolver. Nothing in jaxb will use classpath:.
There is a JAXB sample which shows this sort of thing.
类路径:不是架构位置的有效 url。您必须使用 XML 目录 从 jar 加载模式。
classpath: is not a valid url for schema location. You will have to use XML catalogs to load schemas from jars.