title: JAXB - marshall (uppercase, lowercase, namespaces, ns2)
body: <p>I have about 100 (if not more) Java classes generated from a big XSD file via xjc.</p>
  
  <p>That XSD file has upper-case names for its elements. Now, when I marshall one object from these generated Java classes, I have a few issues.</p>
  
  <p>Sample XML produced by JAXB marshall:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
  &lt;advertiser xmlns:ns2="http://p.t.com/service"&gt;
      &lt;ns2:Name&gt;TEST Adv 001&lt;/ns2:Name&gt;
  &lt;/advertiser&gt;
  </code></pre>
  
  <ol>
  <li><p>The names of the elements (but not those of the sub-elements) are produced by JAXB in lower-case. I need them to be upper-case (as they are in the XSD).  </p></li>
  <li><p>There are some strange ns2: prefixes to the names of the elements e.g. 
  I want the xmlns:ns2 in this example to become just xmlns, and the ns2:Name to become just Name. One answer here on SO suggested putting attributeFormDefault="unqualified" in the XSD, but seems that didn't help me either.   </p></li>
  </ol>
  
  <p>How can I solve these two issues? </p>
  
  <p>I looked here for similar question but don't find one quite identical to mine. Also the answers there look pretty complicated and they ask to change the Java classes which I cannot do. Why should this be so complicated?!   </p>
  
  <p>Note that my Java classes are auto-generated, so I don't want to change them manually.     </p>
  
  <p>I wonder why the XSD says one thing, and the JAXB marshall process produces another thing. Shouldn't the JAXB marshall generate XML which is 100% compliant with the XSD?</p>
  
  <h2>Edit</h2>
  
  <pre><code>@XmlAccessorType(XmlAccessType.FIELD)
  @XmlType(name = "Advertiser", propOrder = {
  
  })
  public class Advertiser {
  
      @XmlElement(name = "TelID")
      protected Integer telID;
  
      @XmlElement(name = "Name")
      protected String name;
  
      @XmlElementRef(name = "Address", namespace = "http://p.t.com/service", type = JAXBElement.class)
      protected JAXBElement&lt;String&gt; address;
  
  .............
  </code></pre>
  
  <h2>Edit 2</h2>
  
  <pre><code>    Advertiser adv = new Advertiser();
      adv.setName("TEST Adv 001");
  
      StringWriter sw = new StringWriter();
      JAXB.marshal(adv, sw);
      System.out.println(sw.toString());
  </code></pre>