I want to Generate XML that look like this :
<mainNode>
<node1></node1>
<node2></node2>
</mainNode>
<mainNode2></mainNode2>
and this is how i generate the mainNode1 , mainNode2 and node1 in my code:
@XmlElementWrapper(name = "mainNode")
@XmlElement(name = "node1")
public List<String> getValue() {
return value;
}
@XmlElement(name = "mainNode2")
public String getValue2() {
return value2;
}
how i could add node2 to the mainNode1 ?
You don’t seem to have a root element in your example. You could do something like this to obtain the structure you want:-
Here’s my test code:-
… and here’s the printout:-