0
我在XML文件中的以下基本上我試圖改變XML文檔解析XML文檔用java的DocumentBuilder
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<root level="DEBUG">
</root>
</configuration>
的屬性這是我的java文件
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..................
對於某些原因警告級別爲空,儘管我在我的xml文檔中有一個名爲root的標籤。
這是我得到我的輸出 The warn level is: [root: null]