Thuộc tính documentElement của XML DOM

Tài liệu tham khảo Document đối tượng

Định nghĩa và cách sử dụng

Thuộc tính documentElement có thể trả về nút gốc của tài liệu.

Cú pháp:

documentObject.documentElement

Mô hình

Trong tất cả các ví dụ, chúng ta sẽ sử dụng tệp XML books.xmlvà hàm JavaScript loadXMLDoc().

Mã đoạn sau có thể hiển thị vị trí XML tài liệu:

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);

Kết quả:

Nodename: bookstore
Nodevalue: null
Nodetype: 1

Tài liệu tham khảo Document đối tượng