简体   繁体   中英

JAXB facilities in unmarshaling

Hello guys how can i unmarshall list of objects in XML. My XML will be like this

<messageContainer class="class1">
    <a>         
        <b />
    </a>
    <MessageB />
</messageContainer>
<messageContainer class="class2">
    <a>         
        <b />
    </a>
    <MessageB />
</messageContainer>

And i want to get list of object in the end.

Any Valid XML file can contain only one XML Root Element.
I assume that u have the above list as a child of an RootElement(say ).

Then your annotated RootElement class should look like this.

 @XmlRootElement(name = "RootElement") public class RootElement{ @XmlElement(name = "messageContainer", required = true) private List<messageContainer> containerList; } 

Where MessageContainer is a class by itself.

Note : The more simpler way to generate these binding class is, write XSD(or generate using online tools) for your XML and compile those XSD with XJC compiler.

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