2017-01-09 87 views
0

我有一個XML文檔,其結構如下。 ReportRaw表示ReportConverted的十六進制值。當我將JAXB綁定應用於此時,我將得到一個表示ReportId的自定義複雜對象,其中包含ReportRaw和ReportConverted的兩個子對象。自定義JAXB綁定

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

我的應用程序不使用ReportedRaw值,所以我想簡化我生成的對象模型,並生成ReportId作爲報告對象的整數。我怎麼能用jaxb自定義綁定來做這件事?

感謝

回答

0

如果你不想要的元素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>