title: How to convert Java objects to XML element attributes using JAXB
body: <p>How to convert java object to xml using <code>JAXB</code> to get the following xml:</p>
  
  <pre><code>&lt;Case&gt;
    &lt;Version&gt;1.0&lt;/Version&gt;
    &lt;Code&gt;457123&lt;/Code&gt;
    &lt;Meta uc=\"Sample\" pip=\"116.0.1.1\" lot=\"P\"/&gt;
  &lt;/Case&gt;
  </code></pre>
  
  <p>There are many answers regarding how to get XML. I have gone through all those. But my question is how to get the XML as what I have shown. It contains a self-closing tag which even contains attributes.</p>
  
  <p>I am using Eclipse IDE. Please suggest a method.</p>
  
  <p>This is my case class:</p>
  
  <pre><code>import auth.Res.Meta;
  
  @XmlRootElement (name="Case")
  
  public class Test {
  
  private Meta mt;
  private String version;
  private String code;
  
  @XmlRootElement
  public class Meta {
  
      @XmlAttribute
      private String uc;
  
      @XmlAttribute
      private String pip;
  
      public String getUc() {
          return uc;
      }
  
      public void setUc(String uc) {
          this.uc = uc;
      }
  
      public String getPip() {
          return pip;
      }
  
      public void setPip(String pip) {
          this.pip = pip;
      }
  }
  
  public Meta getMt() {
      return mt;
  }
  
  public void setMt(Meta mt) {
      this.mt = mt;
  }
  
  public String getVersion() {
      return version;
  }
  
  public void setVersion(String version) {
      this.version = version;
  }
  
  public String getCode() {
      return code;
  }
  
  public void setCode(String code) {
      this.code = code;
  }
  }
  </code></pre>
  
  <p>Solution:</p>
  
  <p>I solved it by creating seperate class for Meta as suggested by LazerBanana in the first answer.</p>