简体   繁体   中英

JAXB @XmlElement(name=..) same xmlElement with different name

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?

**PS 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.

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!

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