I need to bring the data from database table and need to display it in the below XML tree format.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ROOT>
<Rows>
<Row id =1 name=" " desc="" parentId="0">
<Row id = 2 name="" desc="" parentId="1" >
<Row id = 3 name="" desc="" parentId="2" />
</Row>
<Row id = 4 name=" " desc="" parentId="0" />
</Rows>
</ROOT>
Java Class
@XmlRootElement(namespace = "com.abc.ROOT")
@XmlAccessorType(XmlAccessType.FIELD)
public class Rows implements Serializable {
private static final long serialVersionUID = 1;
@XmlAttribute
private int id;
@XmlAttribute
private String name;
@XmlAttribute
private String description;
@XmlAttribute
private int levelNumber;
@XmlAttribute
private Integer parentNodeId;
//If I have the following code, then rather than pulling the single id, it creates one more tree inside and displays all hierarchical structure for its parent node
//@XmlAttribute
//private Rows parentNodeId
}
With the above code I get the plain formatting with random ordering as
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ROOT>
<Rows>
<Row id = 3 name="" desc="" parentId="2" />
<Row id = 1 name=" " desc="" parentId="0"/>
<Row id = 4 name=" " desc="" parentId="0" />
<Row id = 2 name="" desc="" parentId="1"/>
</Rows>
</ROOT>
How do I get the tree stcuture in XML with proper ordering like nested tree stucture? I need to display the nested tree structure.
No comments:
Post a Comment