1

I have list of String in Java and I wanted to convert it into xml using JaxB or any other tool. It should produce output like following. Consider EmployeeData is class already defined there with @XmlRootElement(name = "EmployeeData") and in that class I have

@XmlRootElement(name = "EmployeeData")
@XmlAccessorType (XmlAccessType.NONE)
public class EmployeeData {
   List<String> employee = new ArrayList<>();

   @XmlElement(name = "employee")
   public List<String> getEmployee() {
     return employee;
   }
}

Example:

employee.add("A");
employee.add("B");
employee.add("C");

And I wanted to convert above employee list into following XML format.

<EmployeeData>
    <employee1>A</employee1>
    <employee2>B</employee2>
    <employee3>C</employee3>
<EmployeeData>

And What I'm getting is right now

<EmployeeData>
    <employee>A</employee>
    <employee>B</employee>
    <employee>C</employee>
<EmployeeData>

Can someone provide me solution on this.

  • 1
    Possible duplicate of [Dynamic tag names with JAXB](https://stackoverflow.com/questions/3293493/dynamic-tag-names-with-jaxb) – Arnaud Aug 22 '18 at 09:49

0 Answers0