JAXB: How to change XJC-generated classes names when attr type is specified in XSD? -


i'm beginner jaxb , i'm having annoying issues when generating java classes xjc. provided xsd this:

<xs:element name="item" type="itemtype"/>   ...    <xs:complextype name="itemtype">     <xs:attribute name="id" type="xs:string" use="required">     ...      </xs:complextype> 

and xjc generating class called itemtype.java, want name item.java. is, want generated classes if xsd this:

<xs:element name="item">     <xs:complextype>     <xs:attribute name="id" type="xs:string" use="required">         ...     </xs:complextype> </xs:element> 

there won't reuse of itemtype on other element, it's people constructs xsd likes way. guess there may way custom bindings still haven't found how.

any help?

thanks, miguel

jaxb provides 2 ways accomplish this:

1. inline schema anntotations

you can use jaxb schema annotations control class names.

<xs:schema          xmlns:xs="http://www.w3.org/2001/xmlschema"         xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"         jaxb:version="2.1">      <xs:complextype name="itemtype">         <xs:annotation>             <xs:appinfo>                 <jaxb:class name="item"/>             </xs:appinfo>         </xs:annotation>         <xs:attribute name="id" type="xs:string" use="required"/>     </xs:complextype>  </xs:schema> 

2. external binding file

this customization can done via , external binding file:

<jxb:bindings      xmlns:xs="http://www.w3.org/2001/xmlschema"     xmlns:jxb="http://java.sun.com/xml/ns/jaxb"     version="2.1">      <jxb:bindings schemalocation="your-schema.xsd">             <jxb:bindings node="//xs:complextype[@name='itemtype']">                 <jxb:class name="item"/>             </jxb:bindings>     </jxb:bindings>  </jxb:bindings> 

the xjc command line be:

xjc -d out -b binding.xml your-schema.xsd 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -