简体   繁体   中英

JAXB unmarshalling non wrapped elements

I have following input coming in to my app from 3rd party

    <?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>

I'm unmarshalling the XML into an object X. Notice that the image file elements are not wrapped but numbered, How can I unmarshall those non wrapped and the related elements into a List of objects? which I set into the List type field of the object 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;
}

You can use XmlAnyElement annotation.

Look at here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM