2012-03-06 120 views
0

我試圖XML轉換成java.util.map爲了實現這一目標,我使用XStream的API,但同時轉換我遇到異常如下:轉換XML映射

com.thoughtworks.xstream。 mapper.CannotResolveClassException:根

這裏是我的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; 
    } 
+0

[發佈]的可能的複製[1] [1]:http://stackoverflow.com/questions/25085399/converting-xml-into-java-mapstring-integer/25085677#25085677 。希望幫助 – malatesh 2014-08-01 17:37:16

回答