Convert Java to XML using xstream

Errokemer

New Member
I have started using the xstream library to convert from Java code to XML. My model java class is simple and given below:\[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\]So using simple xstream API I am getting the output of the \[code\]toXML\[/code\] method as below:\[code\]<Person> <firstname>David</firstname> <lastname>Goswami</lastname> <age>34</age></Person>\[/code\]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:\[code\]<Person> <firstname age="34">David</firstname> <lastname>Goswami</lastname> </Person>\[/code\]Any help on how to do this would be highly appreciated.
 
Back
Top