Besoin d'aide pour la mise en forme JAXB de sortie

J'ai quelques objets disons deux, A et B. Ces objets de la même classe. J'ai besoin de maréchal de ces objets à l'aide de JAXB et le XML de sortie doit être de cette forme:

<Root>
    <A>
        <ID> an id </ID>
    </A>
    <B>
        <ID> an id </ID>
    </B>
</Root>

<!-- Then all A and B attributes must be listed !-->
<A>
    <ID> an id </ID>
    <attribute1> value </attribute1>
    <attribute2> value </attribute2>
</A>
<B>
    <ID> an id </ID>
    <attribute1> value </attribute1>
    <attribute2> value </attribute2>
</B>

Comment générer ce format dans JAXB? Toute aide est appréciée.

Mise à jour:
Pour être plus précis, Supposons que nous avons de l'Homme de la classe comme ceci:

@XmlRootElement
public class Human {
    private String name;
    private int age;
    private Integer nationalID;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Integer getNationalID() {
        return nationalID;
    }

    public void setNationalID(Integer nationalID) {
        this.nationalID = nationalID;
    }
}

et notre classe principale est:

public class Main3 {

    public static void main(String[] args) throws JAXBException {
        Human human1 = new Human();
        human1.setName("John");
        human1.setAge(24);
        human1.setNationalID(Integer.valueOf(123456789));

        JAXBContext context = JAXBContext.newInstance(Human.class);
        Marshaller m = context.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

        StringWriter stringWriter = new StringWriter();

        m.marshal(human1, stringWriter);

        System.out.println(stringWriter.toString());
    }

}

Alors la sortie sera:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<human>
    <age>24</age>
    <name>John</name>
    <nationalID>123456789</nationalID>
</human>

Maintenant j'ai besoin de la sortie sera comme ceci:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<human>
    <nationalID>123456789</nationalID>
</human>
<human>
    <nationalID>123456789</nationalID>
    <age>24</age>
    <name>John</name>
</human>

Et cela va m'aider à dessiner un arbre XML des objets sans les attributs de l'opération (ID), puis, mais toutes les définitions ci-dessous l'arbre. Est-ce possible à l'aide de JAXB ou de toute autre mise en œuvre?

InformationsquelleAutor Osama Felfel | 2012-05-10