title: Is it possible to customize the namespace prefix that JAXB uses when marshalling to a String?
body: <p>For example, I've got a simple schema which imports another schema.  The second schema (urn:just:attributes, just-attributes.xsd) just defines an attribute group.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;schema xmlns="http://www.w3.org/2001/XMLSchema" 
      targetNamespace="http://www.example.org/MySchema"
      xmlns:tns="http://www.example.org/MySchema" 
      elementFormDefault="qualified"
      xmlns:ja="urn:just:attributes"&gt;
  
      &lt;import schemaLocation="just-attributes.xsd" namespace="urn:just:attributes"/&gt;
  
      &lt;element name="MyElement"&gt;
          &lt;complexType&gt;
              &lt;attributeGroup ref="ja:AttributeGroup"/&gt;
          &lt;/complexType&gt;
      &lt;/element&gt;
  &lt;/schema&gt;
  </code></pre>
  
  <p>I'm using the Metro xjc Ant task to generate classes off of this schema.  The problem I'm running into is that the third party application I'm interacting with is peculiar about namespaces.  This case I need a String value, so I have to serialize it.  I use boilerplate code for this.</p>
  
  <pre><code>private static &lt;T&gt; String marshal(T object) throws JAXBException{
      OutputStream outputStream = new ByteArrayOutputStream();
      JAXBContext jaxbContext = JAXBContext.newInstance(object.getClass());
      Marshaller marshaller = jaxbContext.createMarshaller();
      marshaller.marshal(object, outputStream);
      return outputStream.toString();
  }
  </code></pre>
  
  <p>Which gives me something along the lines of</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
  &lt;ns2:MyElement xmlns:ns1="urn:just:attributes" xmlns:ns2="http://www.example.org/MySchema" ns1:attrib1="1234" ns1:attrib2="5678"/&gt;
  </code></pre>
  
  <p>The problem I have is that this third party expects something like <code>xmlns:thirdpartyns="urn:just:attributes"</code>, which is to say, they are parsing based on the <strong>name</strong> given to the namespace.  It <strong>has</strong> to be "thirdpartyns" for their software to work.</p>
  
  <p>Does anyone know of a way around this, short of doing a find and replace in the resulting string?  A custom binding rule perhaps?</p>