我正在尝试从多个 xsd 生成一些 bean。不幸的是,它们都有相同的根元素。我已成功创建用于重命名子元素的 xjc 绑定(bind)文件,但找不到选择根节点来更改它的方法。
我尝试了以下但得到了错误:[错误]“/”的 XPath 求值需要产生一个元素。
<jxb:bindings version="1.0" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:com.fnf="http://www.fnf.com/xes">
<jxb:bindings schemaLocation="transcode-submit.xsd" node="/xs:schema">
<jxb:bindings node="/">
<jxb:property name="Newname"/>
</jxb:bindings>
</jxb:bindings>
最佳答案
我想通了。
<jxb:bindings version="1.0" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:com.fnf="http://www.fnf.com/xes">
<jxb:bindings schemaLocation="transcode-submit.xsd" node="/xs:schema">
<jxb:bindings node="//xs:element[@name='OLDROOTNAME']">
<jxb:class name="NEWNAME"/>
</jxb:bindings>
关于java - 如何在使用 XJC 生成 JAXB 代码期间重命名顶级类名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5157560/