0

Is it possible to have same @XmlElement with name that is not constant name? For example I want this:

MyObject myObj = new MyObject("myName");
@XmlElement(name=myObj.getName())
public String elementItem;

This code is not correct, but can I do something like that in some way?

**P.S I must doing this because I have one Rest web service with attribute "name". User can send a different name through this rest ws and I must to create XML with element which name is that inserted name.

Some XML would look like:

<a>
  <b>
  <c>
<a>

And some would look like:

<x>
  <y>
  <z>
<x>

This a,b,c or x,y,z are given in input parameter of REST WS.

  • Do you think is it a good design to change the xml elements ? Why not create a tag like `` and ask consumer of your xml to use the tag ? – Vinay Veluri Sep 02 '14 at 12:21
  • I have requirement to make generic XML which would depend on the user input. I need to send this XML request to IPTV platform, but if IPTV platform change its services, and change look of its XML request, my program must be generic, and to suport this new XML elements. My input than will be a name of element and a value of element, and I will generate a new XML. If IPTV platform will change its services and XML request it must accompany changes without re-deploy applications. It must be generic! :/ – Andrijana Andry Stojanović Sep 03 '14 at 14:00

1 Answers1

1

you can use @XmlElementDecl

and you can refer here on how to do it

http://java.dzone.com/articles/jaxb-and-root-elements

Good luck!

Vihar
  • 3,626
  • 2
  • 24
  • 47