title: Convert Java to XML using xstream
body: <p>I have started using the xstream library to convert from Java code to XML. My model java class is simple and given below:</p>
  
  <pre><code>class Person {
      String firstname;
      String lastname;    
      String age;
      public Person(String first, String last,String age) {
          firstname = first;
          lastname = last;
          this.age =  age;
      }
  }
  </code></pre>
  
  <p>So using simple xstream API I am getting the output of the <code>toXML</code> method as below:</p>
  
  <pre><code>&lt;Person&gt;
    &lt;firstname&gt;David&lt;/firstname&gt;
    &lt;lastname&gt;Goswami&lt;/lastname&gt;
    &lt;age&gt;34&lt;/age&gt;
  &lt;/Person&gt;
  </code></pre>
  
  <p>However, I want to tweak the output and get the string age as an attribute of the field firstname. In essence, I am expecting the xml output as below:</p>
  
  <pre><code>&lt;Person&gt;
    &lt;firstname age="34"&gt;David&lt;/firstname&gt;
    &lt;lastname&gt;Goswami&lt;/lastname&gt;
   &lt;/Person&gt;
  </code></pre>
  
  <p>Any help on how to do this would be highly appreciated.</p>