0

I have a following xml:

<Image>
    <ImageUrl>url</ImageUrl>
    <ImageType>type1</ImageType>
</Image>

Here Image Url is always going to be there in xml. But ImageType is optional field so I can get the following xml as well:

<Image>
    <ImageUrl>url</ImageUrl>
</Image>

or something like this

<Image>
    <ImageUrl>url</ImageUrl>
    <CountryCode>01</CountryCode>
</Image>

Is there is easy way to read the xml such that I can have following:

Image {
    String url; 
    Map<String, String> keyValue; // Key can be CountryCode/ImageType
}

Or there is some other data structure that can be populate dynamically without depending on the key. Usually I use jaxb for xml read/write. I am wondering if there is some library which can be used for aforementioned use case or may be jaxb as well.

PhantomM
  • 825
  • 6
  • 17
  • 34
  • http://stackoverflow.com/questions/7273615/java-unmarshlling-xml-to-object-which-are-dynamic - Check the second answer. I believe that's what you want to do. – K139 May 21 '15 at 19:11
  • You could use [data projection](http://xmlbeam.org) instead of data binding. You may even project any element (like "/parent/*") to a value. – Cfx May 22 '15 at 06:39
  • @K139 Thank you for the suggestions. But It won't work in my case as in aforementioned technique. As we must know element/element path that can be processed by xml to be defined in property file. But in my case I won't be aware of the different elements/element names. – PhantomM May 27 '15 at 21:44

0 Answers0