xml:
<Node name="1">
<Node name="2">
<Node name="4"></Node>
</Node>
<Node name = "3">
<Node name="5"></Node>
</Node>
</Node>
I want to create the following object in java
Node{
String name;
List<Node> nodeList
}
Is there any xml parsing library which could do this.
I have tried xstream and simple, but have not been able to figure it out.
Any help would be appreciated.
This code uses XStream and generates the output you are looking for.
The node class:
The Main class:
EDIT:
Added the deserialization code.
To deserialize you’ll also need to add the XPP3 library to the build path. It is part of XStream.