title: JAXB marshalling XMPP stanzas
body: <p>I am trying to marshall a message using the following snippet:</p>
  
  <pre><code>        JAXBContext jContext = JAXBContext.newInstance(Iq.class);
          Marshaller m = newJAXBContext.createMarshaller();
          m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
          m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
  
          Bind bind = new Bind();
          bind.setResource("resource");
          Iq iq = new Iq();
          iq.setId(iqId);
          iq.setType("set");
          iq.getAnies().add(bind);
  
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          m.marshal(iq, baos);
  </code></pre>
  
  <p>Here, Iq and Bind are the objects formed from the relevant xmpp schemas. My problem is, with jaxb 2.0 and later versions, all the namespaces are declared in the root element:</p>
  
  <pre><code>&lt;iq from='juliet@example.com/balcony'
       id='rg1'
       type='get'  xmlns='jabber:client'  xmlns:ns1='urn:ietf:params:xml:ns:xmpp-bind'&gt; 
      &lt;ns1:bind&gt;
          &lt;ns1:resource&gt;resource&lt;/ns1:resource&gt;
      &lt;/ns1:bind&gt;
  &lt;/iq&gt;
  </code></pre>
  
  <p>But, what is needed here is that the namespaces should occupy the appropriate places:</p>
  
  <pre><code>&lt;iq from='juliet@example.com/balcony'
       id="rg1"
       type="get" xmlns="jabber:client"&gt;
         &lt;bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"&gt;
               &lt;resource&gt;resource&lt;/resource&gt;
         &lt;/bind&gt;
  &lt;/iq&gt;
  </code></pre>
  
  <p>Is there a way to marshall the xmpp stanzas as you see them in the 2nd xml stanza through JAXB 2.0 or later versions?</p>
  
  <p>Long story short, I have 2 problems here:
  1. Declaring the namespaces at appropriate locations.
  2. removing the namespace prefix which I understand can be removed using the NamespacePrefixMapper? Not sure though, an example would be great.</p>