It is easy to parse XML in which tags name are fixed. In XStream, we can simply use @XStreamAlias("tagname")
annotation. But how to parse XML in which tag name is not fixed. Suppose I have following XML :
<result>
<result1>
<fixed1> ... </fixed1>
<fixed2> ... </fixed2>
</result1>
<result2>
<item>
<America>
<name> America </name>
<language> English </language>
</America>
</item>
<item>
<Spain>
<name> Spain </name>
<language> Spanish </language>
</Spain>
</item>
</result2>
</result>
Tag names America
and Spain
are not fixed and sometimes I may get other tag names like Germany, India, etc.
How to define pojo for tag result2
in such case? Is there a way to tell XStream
to accept anything as alias name if tag name is not known before-hand?