title: Need help in formatting JAXB output
body: <p>I have some objects let's say two, A and B. These objects from the same class. I need to marshal these objects using JAXB and the output XML should be in this form:</p>
  
  <pre><code>&lt;Root&gt;
      &lt;A&gt;
          &lt;ID&gt; an id &lt;/ID&gt;
      &lt;/A&gt;
      &lt;B&gt;
          &lt;ID&gt; an id &lt;/ID&gt;
      &lt;/B&gt;
  &lt;/Root&gt;
  
  &lt;!-- Then all A and B attributes must be listed !--&gt;
  &lt;A&gt;
      &lt;ID&gt; an id &lt;/ID&gt;
      &lt;attribute1&gt; value &lt;/attribute1&gt;
      &lt;attribute2&gt; value &lt;/attribute2&gt;
  &lt;/A&gt;
  &lt;B&gt;
      &lt;ID&gt; an id &lt;/ID&gt;
      &lt;attribute1&gt; value &lt;/attribute1&gt;
      &lt;attribute2&gt; value &lt;/attribute2&gt;
  &lt;/B&gt;
  </code></pre>
  
  <p>How to generate this format in JAXB? Any help is appreciated.</p>
  
  <p><strong>Update:</strong>
  To be more specific, Assume we have Human class like this:</p>
  
  <pre><code>@XmlRootElement
  public class Human {
      private String name;
      private int age;
      private Integer nationalID;
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public int getAge() {
          return age;
      }
  
      public void setAge(int age) {
          this.age = age;
      }
  
      public Integer getNationalID() {
          return nationalID;
      }
  
      public void setNationalID(Integer nationalID) {
          this.nationalID = nationalID;
      }
  }
  </code></pre>
  
  <p>and our main class is:</p>
  
  <pre><code>public class Main3 {
  
      public static void main(String[] args) throws JAXBException {
          Human human1 = new Human();
          human1.setName("John");
          human1.setAge(24);
          human1.setNationalID(Integer.valueOf(123456789));
  
          JAXBContext context = JAXBContext.newInstance(Human.class);
          Marshaller m = context.createMarshaller();
          m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
  
          StringWriter stringWriter = new StringWriter();
  
          m.marshal(human1, stringWriter);
  
          System.out.println(stringWriter.toString());
      }
  
  }
  </code></pre>
  
  <p>Then the output will be:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
  &lt;human&gt;
      &lt;age&gt;24&lt;/age&gt;
      &lt;name&gt;John&lt;/name&gt;
      &lt;nationalID&gt;123456789&lt;/nationalID&gt;
  &lt;/human&gt;
  </code></pre>
  
  <p>Now I need the output to be like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
  &lt;human&gt;
      &lt;nationalID&gt;123456789&lt;/nationalID&gt;
  &lt;/human&gt;
  &lt;human&gt;
      &lt;nationalID&gt;123456789&lt;/nationalID&gt;
      &lt;age&gt;24&lt;/age&gt;
      &lt;name&gt;John&lt;/name&gt;
  &lt;/human&gt;
  </code></pre>
  
  <p>And this will help me draw a tree of XML objects without the attributes (only by ID) and then but all the definitions below the tree. Is this possible using JAXB or any other implementation?</p>