我正在尝试将XML转换为java.util.map以实现此目的我使用XStream API但在转换时我遇到了如下异常:
com.thoughtworks.xstream.mapper.CannotResolveClassException:root
这是我的XML示例:
<?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>
这是我的代码:
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;
}