I’m a newbie so please be patient.
I have the following code retrieving the nodes and its fine. I’ve attempted to get the ‘status’ node to have it’s first letter capitalized with little success, it force closes.
What I’ve done is convert the element to a string. I figured out that I could use the capitalization code for all the elements ‘e’ but I’d rather use it for status.
Why is it forcing close?
Could someone please help me with this?
NodeList nodes = doc.getElementsByTagName("line");
for (int i = 0; i < nodes.getLength(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element)nodes.item(i);
map.put("id", XMLFunctions.getValue(e, "id"));
map.put("name", XMLFunctions.getValue(e, "name"));
map.put("status", XMLFunctions.getValue(e, "status"));
map.put("message", XMLFunctions.getValue(e, "message"));
mylist.add(map);
//element to string
Document document = e.getOwnerDocument();
DOMImplementationLS domImplLS = (DOMImplementationLS) document
.getImplementation();
LSSerializer serializer = domImplLS.createLSSerializer();
String str = serializer.writeToString(e);
//capitalization
if (str.length() <= 1) {
str = str.toLowerCase();
} else {
str = str.substring(0, 1).toLowerCase() + str.substring(1);
}
I solved this using the following code: