带有前缀命名空间的xml元素的jaxb映射

时间:2015-12-17 07:11:39

标签: jaxb jaxb2

如何在使用xml映射它时在pojo类中进行注释,该xml具有带前缀为namespace的xml元素,如下所示:

<PPS xmlns:oag="http://www.openapplications.org/oagis/9" languageCode="en-US">
  <oag:creationdatetime>2015-01-05T11:48:30</oa:creationdatetime>
</PPS>

我试过如下,但当我尝试解组时,creationdatetime值为null:

@XmlRootElement(name="PPS")
public class PPS { 

private String creationdatetime; 

public String getCreationdatetime() {
return creationdatetime;
}

@XmlElement(name="creationdatetime",namespace="oag")
public void setCreationdatetime(String creationdatetime) {
this.creationdatetime = creationdatetime;
}

}

1 个答案:

答案 0 :(得分:0)

namespace参数值应该是url而不是@XmlElement(namespace =“”)的前缀:

@XmlRootElement(name="PPS")
public class PPS { 

private String creationdatetime; 

public String getCreationdatetime() {
return creationdatetime;
}

@XmlElement(name="creationdatetime",namespace="http://www.openapplications.org/oagis/9")
public void setCreationdatetime(String creationdatetime) {
this.creationdatetime = creationdatetime;
}

}