XML DOM documentElement 屬性

Document 對象參考手冊

定義和用法

documentElement 屬性可返回文檔的根節點。

語法:

documentObject.documentElement

實例

在所有的例子中,我們將使用 XML 文件 books.xml,以及 JavaScript 函數 loadXMLDoc()

以下代碼片段可顯示 XML 文檔的位置:

xmlDoc=loadXMLDoc("/example/xdom/books.xml");
var x=xmlDoc.documentElement;
document.write("Nodename: " + x.nodeName + "<br />");
document.write("Nodevalue: " + x.nodeValue + "<br />");
document.write("Nodetype: " + x.nodeType);

輸出:

Nodename: bookstore
Nodevalue: null
Nodetype: 1

Document 對象參考手冊