title: JAXB Root Class Rename using binding.xml
body: <p>I use the Dali plugin in Eclipse to generate Java classes using an xsd file, which essentially just invokes xjc on the schema file.  I used the advice <a href="http://blog.bdoughan.com/2011/07/jaxb-xjc-and-nested-classes.html" rel="nofollow">here</a> to resolve naming conflicts by applying an XML binding file to the class generation.  This worked well, but I tried to take it a step further by renaming the root element, and the result was that I lost the XmlRootElement annotation.  I tried using annox to add the root element annotation back in, but I get this error:  Unsupported binding namespace "<a href="http://annox.dev.java.net" rel="nofollow">http://annox.dev.java.net</a>". Perhaps you meant "<a href="http://java.sun.com/xml/ns/jaxb/xjc" rel="nofollow">http://java.sun.com/xml/ns/jaxb/xjc</a>"?</p>
  
  <p>Here is my initial binding.xml file (without annox):</p>
  
  <pre><code>&lt;jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
      version="2.1"&gt;
      &lt;!-- Force all classes to be generated at the top level, this will potentially cause name conflicts --&gt;
      &lt;jaxb:globalBindings localScoping="toplevel"/&gt;
      &lt;jaxb:bindings schemaLocation="mySchema-1.0.0.xsd"&gt;
          &lt;!-- Rename the root element --&gt;
          &lt;jaxb:bindings node="//xs:element[@name='MyRootClassNameIsReallyLong']/xs:complexType"&gt;
              &lt;jaxb:class name="ShorterName"/&gt;
          &lt;/jaxb:bindings&gt;
          &lt;!-- Rename the Bar class to resolve a naming conflict --&gt;
          &lt;jaxb:bindings node="//xs:element[@name='Foo']/xs:complexType/xs:sequence/xs:element[@name='Bar']/xs:complexType"&gt;
              &lt;jaxb:class name="FooBar"/&gt;
          &lt;/jaxb:bindings&gt;
      &lt;/jaxb:bindings&gt;
  &lt;/jaxb:bindings&gt;
  </code></pre>
  
  <p>By the way, it's worth noting that the schema file came from a third party, so I have no interest in modifying it.  Likewise, I'd rather not tamper with the generated Java files, so that's why I am interested in the binding xml approach.</p>
  
  <p>Edit (9/11/2013) - Here is the binding XML with annox:</p>
  
  <pre><code>&lt;jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
      xmlns:annox="http://annox.dev.java.net"
      version="2.1"&gt;
      &lt;!-- Force all classes to be generated at the top level, this will potentially cause name conflicts --&gt;
      &lt;jaxb:globalBindings localScoping="toplevel"/&gt;
      &lt;jaxb:bindings schemaLocation="mySchema-1.0.0.xsd"&gt;
          &lt;!-- Rename the root element --&gt;
          &lt;jaxb:bindings node="//xs:element[@name='MyRootClassNameIsReallyLong']/xs:complexType"&gt;
              &lt;jaxb:class name="ShorterName"/&gt;
              &lt;annox:annotate&gt;
                  &lt;annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement" name="MyRootClassNameIsReallyLong" /&gt;
              &lt;/annox:annotate&gt;
          &lt;/jaxb:bindings&gt;
          &lt;!-- Rename the Bar class to resolve a naming conflict --&gt;
          &lt;jaxb:bindings node="//xs:element[@name='Foo']/xs:complexType/xs:sequence/xs:element[@name='Bar']/xs:complexType"&gt;
              &lt;jaxb:class name="FooBar"/&gt;
          &lt;/jaxb:bindings&gt;
      &lt;/jaxb:bindings&gt;
  &lt;/jaxb:bindings&gt;
  </code></pre>