将 ANT 与多个 XSD 和单个 XJB 结合使用
我有一个自定义的外部 XJB 文件,其中的架构名称如下:
jxb:bindings schemaLocation="completeCheck.xsd" node="/xs:schema"
只是想知道,有没有办法使用 ANT(使用 ANT XJC)在运行时替换 XJB 文件中的架构名称,或者编写一个 xjb 绑定文件,这样我就不必在其中硬编码架构名称。基本上,我想看看是否可以将单个 xjb 文件用于多个 XSD。
目前,我到处都有相同的 xjb 文件,并且在 build.xml 中到处引用了不同的硬编码模式名称。任何指点都将受到高度赞赏。我正在使用 JAXB 2.x
I have a custom external XJB file that has the schema name within it as follows :
jxb:bindings schemaLocation="completeCheck.xsd" node="/xs:schema"
Just wondering, is there a way to substitute the schema name at runtime within the XJB file using ANT(using ANT XJC) OR have a xjb binding file written such that I do not have to hardcode the schema name in it. Basically, I am trying to see if I can use a single xjb file for multiple XSDs.
Currently, I have the same xjb file all over the place with a different hardcoded schema name referred all over the place in build.xml. Any pointers are highly appreciated. I am using JAXB 2.x
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通过用某种标记(例如!!!)替换 schemaLocation 属性的值,从 xjb 文件创建模板,并使用其他名称/扩展名保存它。使用诸如 schema-name 之类的属性定义一个宏,该宏将使用 ant 的替换来使用您的架构名称更改模板文件中的标记,并将其保存为绑定文件以供 xjc 随后使用。
Make a template from your xjb file by replacing the value of your schemaLocation attribute with some sort of marker (e.g. !!!) and save it using some other name/extension. Define a macro with an attribute such as schema-name that will use ant's replace to change the marker in the template file with your schema name and save that as the binding file to be subsequently used by xjc.
通常,在最新版本的XJC中,您可以使用模式组件指示符。更多信息在这里:
https://jaxb.java.net/nonav/2.2.1 /docs/vendorCustomizations.html#scd 和 https://jaxb.java.net/guide/Using_SCD_for_customizations.html
Normally, in the latest versions of XJC, you can use schema component designator. More info here :
https://jaxb.java.net/nonav/2.2.1/docs/vendorCustomizations.html#scd and https://jaxb.java.net/guide/Using_SCD_for_customizations.html