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
舉報(bào)
2019-07-08
我在API里看了一下Document(org.w3c.dom.Document)發(fā)現(xiàn)它是繼承Node,而Node下的各個接口(interface)有對應(yīng)的節(jié)點(diǎn)名稱(nodeName)、節(jié)點(diǎn)值(nodeValue)以及屬性(attributes)。
而Document對應(yīng)的節(jié)點(diǎn)名稱為"#document",其節(jié)點(diǎn)值得到的最終還是null,屬性為null。
如果只是將代碼中Document的對象直接輸出,那么會顯示對應(yīng)的名稱以及對應(yīng)的值。
注:原本調(diào)用System.out.println()方法應(yīng)該是輸出Object類中的toString()方法定義的:
? ????getClass().getName() + '@' + Integer.toHexString(hashCode())
但是這里輸出的:
????[#document: null]
應(yīng)該是某個父類(估計(jì)是NodeImpl類或者其他某個類)中重寫的toString()方法
public String toString() {
????return "[" + getNodeName() + ": " + getNodeValue() + "]";
}