title: Converting XML to Java Map<String, Integer> using XStream
body: <p>I'm converting XML code to a Java Map. The XML matches a large number of random words with a number (a probability distribution) and looks like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  &lt;root&gt;
     &lt;Durapipe type="int"&gt;1&lt;/Durapipe&gt;
     &lt;EXPLAIN type="int"&gt;2&lt;/EXPLAIN&gt;
     &lt;woods type="int"&gt;2&lt;/woods&gt;
     &lt;hanging type="int"&gt;3&lt;/hanging&gt;
     &lt;hastily type="int"&gt;2&lt;/hastily&gt;
     &lt;localized type="int"&gt;1&lt;/localized&gt;
     .......
  &lt;/root&gt;
  </code></pre>
  
  <p>I'm trying to implement this with XStream. Here's the Java code that my main program currently uses:</p>
  
  <pre><code>    XStream xstream = new XStream();
      Map&lt;String, Integer&gt; englishCorpusProbDist; 
      xstream.registerConverter(new MapEntryConverter());
      englishCorpusProbDist = (Map&lt;String, Integer&gt;)xstream.fromXML(new File("C:/Users/David Naber/Documents/IREP Project/frequencies.xml"));
  </code></pre>
  
  <p>And here's my MapEntryConverterClass:</p>
  
  <pre><code>public class MapEntryConverter implements Converter {
    public boolean canConvert(Class clazz) {
      return Map.class.isAssignableFrom(clazz);
    }  
  
    public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) {
      Map&lt;String, Integer&gt; map = (Map&lt;String, Integer&gt;) value;
      for (Map.Entry&lt;String, Integer&gt; entry : map.entrySet()) {
        writer.startNode(entry.getKey().toString());
        writer.setValue(entry.getValue().toString());
        writer.endNode();
      }
    }
  
    public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
      Map&lt;String, Integer&gt; map = new HashMap&lt;String, Integer&gt;();
  
      while (reader.hasMoreChildren()) {
        reader.moveDown();
        map.put(reader.getNodeName(), reader.getValue());
        reader.moveUp();
       }
      return map;
     }
  }
  </code></pre>
  
  <p>I"m getting an error in the above function, on the line "map.put(reader.getNodeName(), reader.getValue());". The error says: "The method put(String, Integer) in the type Map is not applicable for the arguments (String, String)."</p>
  
  <p>So I really have two questions here. First of all, why is this error happening and how can I fix it? Secondly, what more will I need to implement to finally get XStream to convert this to XML?</p>
  
  <p>Any help is much appreciated. Thank you in advance!</p>