【问题标题】:jaxb mapping for xml element with prefix of namespace带有命名空间前缀的 xml 元素的 jaxb 映射
【发布时间】:2015-12-17 07:11:38
【问题描述】:

如何在 pojo 类中进行注释,同时将其映射到 xml,该 xml 元素具有如下命名空间前缀:

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

我已经尝试如下,但是当我尝试解组它时,creationdatetime 值变为空:

@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;
}

}

【问题讨论】:

    标签: jaxb jaxb2


    【解决方案1】:

    命名空间参数值应该是 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;
    }
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多