parse方法 輸出為null
Document?d?=?db.parse(new?File("C:\\Users\\Lenovo\\Desktop\\demo.xml")); System.out.println(d);
[#document: null]
Document?d?=?db.parse(new?File("C:\\Users\\Lenovo\\Desktop\\demo.xml")); System.out.println(d);
[#document: null]
2019-07-03
舉報
2019-07-08
我在API里看了一下Document(org.w3c.dom.Document)發現它是繼承Node,而Node下的各個接口(interface)有對應的節點名稱(nodeName)、節點值(nodeValue)以及屬性(attributes)。
而Document對應的節點名稱為"#document",其節點值得到的最終還是null,屬性為null。
如果只是將代碼中Document的對象直接輸出,那么會顯示對應的名稱以及對應的值。
注:原本調用System.out.println()方法應該是輸出Object類中的toString()方法定義的:
? ????getClass().getName() + '@' + Integer.toHexString(hashCode())
但是這里輸出的:
????[#document: null]
應該是某個父類(估計是NodeImpl類或者其他某個類)中重寫的toString()方法
public String toString() {
????return "[" + getNodeName() + ": " + getNodeValue() + "]";
}