I am trying to convert XML into java.util.map in order to achieve this I am using XStream API but while converting I encountered an exception as follows:
com.thoughtworks.xstream.mapper.CannotResolveClassException: root
Here is my XML Sample:
<?xml version='1.0' encoding="UTF-8"?>
<root>
<mobile>
<id>m0001</id>
<manufacture>NOKIA</manufacture>
<model>N90</model>
<touchscreen>Yes</touchscreen>
<keyboard>Yes</keyboard>
<quantity>25</quantity>
<price>RM 2200</price>
</mobile>
</root>
and here is my code:
public Map<String, Object> convertXml(File xmlFile) {
XStream xStream = new XStream(new DomDriver());
Map<String, Object> xmlMap = (Map<String, Object>) xStream.fromXML(xmlfile);
return xmlMap;
}