XStreams and Attributes

Viewed 11

I need to parse an XML-file, last time I did anything like this I used XStream so I thought I'd go that road again. Now the last time was something like 10 years ago so my memory isn't all that fresh and I need some help with attributes. The XML file has lots of fields with attributes and it seems like I need to create a complex (class) for each field. XML like this:

 <type>
    <name>BLOCK_N</name>
    <i-name>Block Size</i-name>
    <documentation enc="utf-8">Some docks.</documentation>
    <datatype byteswap="true">UINT32_T</datatype>
</type>

My annotate code looks like this:

 public class Type {

    @XStreamAlias("name")
    public String name;

    @XStreamAlias("i-name")
    public String iName;

    @XStreamAlias("documentation")
    @XStreamImplicit
    public List<String> documentation;

    @XStreamAlias("comments")
    @XStreamImplicit
    public List<String> comments;

    @XStreamAlias("datatype")
    @XStreamAsAttribute
    public String datatype;

    @XStreamAlias("byteswap")
    @XStreamAsAttribute
    public String byteswap;
}

Here I'm unable to retrieve the byteswap attribute. I would like to avoid having to create a special class just for that. Is there anyway around it?

0 Answers
Related