I think you misunderstand your output. With this
Node warnLevel = doc.getElementsByTagName("root").item(0);
you get the single root
tag in your xml. The toString()
of that object is the name of the tag and the node's value, but apparently it always returns null
for element nodes.
What you want is to get the attribute level
.
Node warnLevel = doc.getElementsByTagName("root").item(0).getAttributes().getNamedItem("level");
System.out.println("The warn level is: " + warnLevel);
which prints
level="DEBUG"