开发者

how to get anyType value using jaxb?

I have an xml that looks like this:

<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>

the object generated by xjc is:

public class Root {
  @XmlElement(name="tag1")
  protected short tag1;

  @XmlElement(name="tag2")
  protected String tag2;

  @XmlElement(name="tag3")
  protected Object tag3;
}

when i unmarshal the xml i get some kind of an xml element in tag3. I need something generic to get the values 开发者_开发百科in tag3 into a list.

any ideas?

thanks.


Create class AnyType. And decalre tag3 as array of AnyType

 @XmlElement(name="tag3")
 protected AnyType[] tag3;


Well, the answer truns out to be simple. I just change

  @XmlElement(name="tag3")
  protected Object tag3;

to:

 @XmlWrapper(name = "tag3")
 @XmlElements(@XmlElement(name="anyType"))
  protected List<Object> list;

my problem was with the object genertaed by xjc.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜