【问题标题】:Custom JAXB Bindings自定义 JAXB 绑定
【发布时间】:2017-01-09 21:42:00
【问题描述】:

我有一个 XML 文档,其结构如下。 ReportRaw 表示 ReportConverted 的十六进制值。当我对此应用 JAXB 绑定时,我将获得一个表示 ReportId 的自定义复杂对象,其中包含 ReportRaw 和 ReportConverted 的两个子对象。

<Report>
    <ReportId>
        <ReportRaw>FA3</ReportRaw>
        <ReportConverted>4003</ReportConverted>
    </ReportId>
</Report>

我的应用程序不使用 ReportedRaw 值,因此我想简化生成的对象模型并将 ReportId 生成为报告对象上的整数。我该如何使用 jaxb 自定义绑定来执行此操作?

谢谢

【问题讨论】:

    标签: xml xml-parsing jaxb


    【解决方案1】:

    如果您在编组或解组期间不想要元素 ReportRaw,则可以使用 @XmlTransient 进行注释。

    要使用jaxb 绑定来执行此操作,您将需要使用jaxb2-annotate-plugin。下面是用法。

     <jaxb:bindings node=".//xs:element[@name='ReportRaw']" >              
           <annox:annotate target="field">@javax.xml.bind.annotation.XmlTransient</annox:annotate>
       </jaxb:bindings> 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多