1

I am using simple-xml library to parse xml,where data is list which contains list of different types, data consist of list of images and list of videos,here is xml I represent my java class like this

@ElementList(required = false, name = "data")
public ArrayList<Data> data;
public class Data {
public String link;
public String url;}

It works ,while I want to map my xml to this class

public class Data{
public ArrayList<Image>images;
public ArrayList<Video>videos;}

<data>
      <image>
        <link></link>
        <mask></mask>
      </image>
      <image>
        <link></link>
        <mask></mask>
      </image>
      <video>
        <url></url>
        <mask></mask>
      </video>
      <video>
        <url></url>
        <mask></mask>
      </video> </data>

1 Answer 1

2

Try this one

  @Root
  public class Example {
     @ElementListUnion({
        @ElementList(entry="images", type=Image.class, inline=true),
        @ElementList(entry="videos", type=Vidio.class, inline=true),
     })
     private List<Data> data;
  }
 //vidio
 @Default
  public class Vidio {
    private String link;
    private String mask;
  }
  //image
  @Default
  public class Image {
    private String url;
    private String mask;

  }

source : http://simple.sourceforge.net/download/stream/doc/examples/examples.php

check the link your self it might help.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks ,only I don't understand why we need to write these code @ElementListUnion({ @ElementL(name="link", type=Image.class), @Element(name="mask", type=Vidio.class), }) in Video part and @ElementListUnion({ @Element(name="url", type=Image.class), @Element(name="mask", type=Vidio.class), }) in Image part
@A.A.I.A I edit my answer check it now. again this is from the link.
@A.A.I.A Please aprove my answer as accepted, I need the reputations buddy!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.