I've written an XML parser which parses an XML documents and returns me a Map of and ID and Name. For some reason it's skipping duplicates IDs.
Edit:
public static Multimap<String,String> getMap(String pathToFile) {
Multimap<String,String> map = new ArrayListMultimap.create();
try {
Document doc = getDocument(pathToFile);
NodeList nList = doc.getElementsByTagName("Definition");
for(int i=0;i<nList.getLength();i++) {
Node nNode = nList.item(i);
if(nNode.getNodeType() == Node.ELEMENT_NODE) {
Element eElement = (Element) nNode;
String nodeID = eElement.getElementsByTagName("Key").item(0).getTextContent();
NodeList n = eElement.getElementsByTagName("Value");
for(int j=0;j<n.getLength();j++) {
String name = n.item(0).getTextContent();
if(name.equalsIgnoreCase("")) {
name = "blank"; // check for empty values
}
map.put(nodeID, name);
}
}
}
}
catch (IOException e) {
e.printStackTrace();
}
return map;
}
public static List<String> getIDList(String pathToFile) {
List<String> list = new ArrayList<String>();
Multimap<String, String> map = getMap(pathToFile);
for(String id : map.keySet()) {
list.add(id);
}
return list;
}
My question is, why is this happening? Why duplicate is being ignored?