How do I rename top level Classname during JAXB code generation using XJC?

核能气质少年 提交于 2019-12-07 14:49:26

问题


I am trying to generate some beans from several xsd's. Unfortunately they all have the same root element. I have successfully created a xjc bindings file for renaming sub-elements but cannot find a way to select the root node to change that.

I tried the following but get the error: [ERROR] XPath evaluation of "/" needs to result in an element.

<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>                                                           


回答1:


I figured it out.

<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>



来源:https://stackoverflow.com/questions/5157560/how-do-i-rename-top-level-classname-during-jaxb-code-generation-using-xjc

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