# how to unmarshal this with xstream?



## DaRolla (18. Mrz 2010)

hi,

I am using xstream with and without annotation, and it's pretty easy to use.

Right now I got a case I get nuts on.

Here's my XML:

[xml]<content>
  <tag type="p">
    ...
  </tag>
  <tag type="p">
    ...
  </tag>
  <tag type="h">
    ...
  </tag>
  <tag type="p">
    ...
  </tag>
</content>[/xml]

So content has a list of tags. A tag itself has the attribute type which can be p oder h. And tag has content. And this is the problematic part 


```
@XStreamAlias("content")
public class Content {

        @XStreamImplicit
        public List<Tag> listTag = new ArrayList<Tag>();
}

@XStreamAlias("tag")
public class Tag {

        @XStreamAsAttribute
        public String type;

        public String tag;
}
```

Or without annotations:


```
xstream.alias("content", Content.class);
xstream.addImplicitCollection(Content.class, "listTag", Tag.class);

xstream.alias("tag", String.class);
xstream.useAttributeFor(Tag.class, "type");
```

But after unmarshalling the content.listTag.get(i).tag is always NULL where content.listTag.get(i).type is p oder h as expected.

Somehow its unmarshalling only the attribute but not the child node.

Who can help me on this?

Greetings and lots of thanks,
Marco Schmitz


----------



## Joew0815 (19. Mrz 2010)

Wie wärs mit deutsch?


----------



## Noctarius (19. Mrz 2010)

I guess it's cause in the Tag-Tag there is no other Tag-Tag (omg) which could be mapped. The code you use needs xml like this:
[xml]<content>
  <tag type="p">
    <tag>...</tag>
  </tag>
</content>[/xml]

This should help you I guess: XStream : node with attributes and text node? - Stack Overflow


----------

