public static HashMap readXML(File file)throws IOException
{
BufferedInputStream is = new BufferedInputStream(new FileInputStream(file));
HashMap hashmap = new HashMap();
HashMap hm = new HashMap();
try
{
SAXReader reader = new SAXReader();
Document doc = reader.read(is);
Element root = doc.getRootElement();
Element e;
String sPropName;
String sPropValue;
String index="0";
List list=root.elements();
for(int i=0;i<list.size();i++)
{
e=(Element)list.get(i);
sPropName=e.getName();
sPropValue=e.getTextTrim();
hm.put(sPropName,sPropValue);
hashmap.put(index+i,hm);
hashmap.putAll(getElements(index+i,e));
}
}
catch(Exception e)
{
}
return hashmap;
}
public static HashMap getElements(String index ,Element e)
{
HashMap hm = new HashMap();
HashMap hashmap = new HashMap();
List list =e.elements();
Element temp;
String sName="";
String sValue="";
for (int i=0;i<list.size();i++)
{
temp=(Element)list.get(i);
sName=temp.getName();
sValue=temp.getTextTrim();
hm.put(sName,sValue);
hashmap.put(index+i,hm);
if(temp.elements().size()>0)
hashmap.putAll(getElements(index+i,temp));
}
return hashmap;
}