I have the following in my xml file and basically I am trying to change an attribute of the xml document
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<root level="DEBUG">
</root>
</configuration>
This is my java file
public static void changeXMLLogLevel(String pathToXMLDocument, String newWarnLevel){
// make sure that xml file is present
File f = new File(pathToXMLDocument);
if (f.exists()) {
try {
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.parse(pathToXMLDocument);
// Get the warn level
Node warnLevel = doc.getElementsByTagName("root").item(0);
System.out.println("The warn level is: " + warnLevel);
// more code..................
For some reason the warn level is null although I have a tag in my xml document called root.
This is what I get for my output
The warn level is: [root: null]