I'm trying to create concise summaries for xml documents. The idea is as described below. The input xml file i'm using is.
<?xml version = "1.0" encoding="UTF-8"?>
<Employee-Detail>
<Employee>
<Emp_Id> E-001 </Emp_Id>
<Emp_Name> Vinod </Emp_Name>
<Emp_E-mail>
Vinod1@yahoo.com </Emp_E-mail>
</Employee>
<Employee>
<Emp_Id> E-002 </Emp_Id>
<Emp_Name> Amit </Emp_Name>
<Emp_E-mail>
Amit2@yahoo.com </Emp_E-mail>
</Employee>
<Employee>
<Emp_Id> E-003 </Emp_Id>
<Emp_Name> Deepak </Emp_Name>
<Emp_E-mail>
Deepak3@yahoo.com </Emp_E-mail>
</Employee>
</Employee-Detail>
I'm trying to write code in
java that converts above file into something like the following.
<?xml version = "1.0" encoding="UTF-8"?>
<Employee-Detail>
<Employee>
<Emp_Id> E-001,E-002,E-003 </Emp_Id>
<Emp_Name> Vinod,Amit,Deepak </Emp_Name>
<Emp_E-mail>
Vinod1@yahoo.com,Amit2@yahoo.com,Deepak3@yahoo.com </Emp_E-mail>
</Employee>
</Employee-Detail>
That is, I'm trying to merge siblings with same name by keeping only one such node and adding the children of the other siblings with same name to it.
I'm using the DOM API. How do I keep track of all the elements names and their respective children?