XML Schema reference

核能气质少年 提交于 2019-12-10 20:53:03

问题


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?


回答1:


Check out my answer to a previous question on how a ResourceResolver can be used to solve this problem:

  • JAXB SchemaFactory source order must follow import order between schemas?

Your implementation of LSResourceResolver will handle loading the schema from the classpath and converting it to the appropriate result.




回答2:


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.




回答3:


classpath: is not a valid url for schema location. You will have to use XML catalogs to load schemas from jars.



来源:https://stackoverflow.com/questions/3979053/xml-schema-reference

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!