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;
}
JAXB不能用於這種情況,因爲從Java到XML的映射變得不確定('pictures.get(0).getCaption()'應該映射到'',但'pictures.get(1) '... - 不)。只有您的應用程序可以控制此映射。 –
2012-04-07 22:26:31