2012-04-07 65 views
0

我有以下输入来自第三方进来到我的应用程序JAXB解组非包裹元素

<?xml version="1.0"?> 
    <document> 
     <name>Foobar</name> 
     <descriprion>Foobar Foobar</descriprion> 
     <lead>Lorem</lead> 
     <bodytext>Foobar Foobar Lorem</bodytext> 

     <ImageFile1>pic123</ImageFile1> 
     <caption1><![CDATA[yadda yadda]]></caption1> 
     <photographer1><![CDATA[Mr. Foobar]]></photographer1> 
     <crop1>1.01 0 0 1.01 0 -80000 0</crop1> 
     <width1>283.86</width1> 
     <height1>164.51</height1> 

     ... 

     <ImageFile38>000bemdt</ImageFile38> 
     <caption38><![CDATA[Ljubov Kavaljova]]></caption38> 
     <photographer38><![CDATA[]]></photographer38> 
     <crop38>1.24 0 0 1.24 -369326 -69264 0</crop38> 
     <width38>44.10</width38> 
     <height38>68.35</height38> 
    </document> 

我解编XML为对象X.注意,图像文件中的元素不会换,但编号!我怎样才能将这些非包装元素和相关元素解组到对象列表中,我将其设置到对象X的列表类型字段中?

public class Article() 
{ 
    private String name; 
    private String description; 
    private String lead; 
    private String bodytext; 
    private List<Picture> pictures; 
} 

public class Picture() 
{ 
    private String fileName; 
    private String caption; 
    private String photographer; 
    private String crop; 
    private String width; 
    private String height; 
} 
+0

JAXB不能用于这种情况,因为从Java到XML的映射变得不确定('pictures.get(0).getCaption()'应该映射到'',但'pictures.get(1) '... - 不)。只有您的应用程序可以控制此映射。 – 2012-04-07 22:26:31

回答

1

您可以使用XmlAnyElement注释。

看看here