views:

105

answers:

2

For example, how would form an object from XML written like this?

<name length="4">Ryan</name>

I would normally alias a class using an annotation to "name" and then have a length and a field for the name. However, this will not work because the second field has no name.

*Edit confusing wording

+1  A: 

It has been a while since I used xstream (2+ years) but I do remember using converters to change the way that objects are serialized. Check out http://xstream.codehaus.org/converters.html. Also this tutorial, http://xstream.codehaus.org/converter-tutorial.html, has some examples with attributes down towards the bottom.

Randy Simon
A: 

Why not use JAXB?

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlValue;

@XmlRootElement
public class Name {

    @XmlValue
    private String name;

    @XmlAttribute
    private int length;
}
Blaise Doughan
Blaise Doughan