我有一个看起来像这样的xml:
<Root>
<tag1>4</tag1>
<tag2>aa</tag2>
<tag3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<anyType xsi:type="xsd:string">bla bla bla</anyType>
<anyType xsi:type="xsd:string">3</anyType>
</tag3>
</Root>xjc生成的对象为:
public class Root {
@XmlElement(name="tag1")
protected short tag1;
@XmlElement(name="tag2")
protected String tag2;
@XmlElement(name="tag3")
protected Object tag3;
}当我对xml进行解组时,我得到了tag3中的某种xml元素。我需要一些通用的东西来将tag3中的值放到一个列表中。
有什么想法吗?
谢谢。
发布于 2011-08-17 14:13:50
好吧,答案看起来很简单。我只是改变
@XmlElement(name="tag3")
protected Object tag3;至:
@XmlWrapper(name = "tag3")
@XmlElements(@XmlElement(name="anyType"))
protected List<Object> list;我的问题是xjc生成的对象。
发布于 2011-08-16 07:26:13
创建类AnyType。和decalre tag3作为AnyType的数组
@XmlElement(name="tag3")
protected AnyType[] tag3;https://stackoverflow.com/questions/7066635
复制相似问题