I have a chunk of XML, that is turned into a String
via substring
.
I need to compare some data within it, so need to turn it into the HashMap
. This is the XML:
title="Language Dependence" totalvotes="32">
<results>
<result level="1" value="No necessary in-game text" numvotes="0" />
<result level="2" value="Some necessary text - easily memorized or small crib sheet" numvotes="7" />
<result level="3" value="Moderate in-game text - needs crib sheet or paste ups" numvotes="22" />
<result level="4" value="Extensive use of text - massive conversion needed to be playable" numvotes="2" />
<result level="5" value="Unplayable in another language" numvotes="1" />
</results>
</poll>
I have written the HashMap
Code, but it does not seem to work. What am I doing wrong?
Response response = RestAssured.get(api address);
String code = response.asString();
String partialCode = code.substring(15967, 16535);
String partialCodeAm = partialCode.replaceAll("/>", "");
String partialCodeAp = partialCodeAm.replaceAll("<", "");
String partialCodeAf = partialCodeAp.replaceAll("\"", "");
String partialCodeAd = partialCodeAf.replaceAll("results>", "");
String partialCodeAu = partialCodeAd.replaceAll(">", "");
String partialCodeAc = partialCodeAu.replaceAll("/results>", "");
String partialCodeAk = partialCodeAc.replaceAll("/", "");
String[] parts = partialCodeAk.split(",");
Map<String, String> map = new HashMap<>();
for (String part : parts) {
String[] voteData = part.split(":");
String level = voteData[0].trim();
String numvotes = voteData[0].trim();
map.put(level, numvotes);
}