XML DOM ownerDocument 属性
定义和用法
ownerDocument 属性返回节点所属的根元素(document 对象)。
语法:
attrObject.ownerDocument
实例
在所有的例子中,我们将使用 XML 文件 books.xml,以及 JavaScript 函数 loadXMLDoc()。
下面的代码片段返回 XML 文档中第一个 category 属性节点的根元素:
xmlDoc=loadXMLDoc("books.xml");
x=xmlDoc.getElementsByTagName('book');
document.write(x.item(0).attributes[0].ownerDocument);
document.write("<br />");
document.write(x.item(0).attributes[0].ownerDocument.nodeName);
document.write("<br />");
document.write(x.item(0).attributes[0].ownerDocument.nodeType);
以上代码的输出:
[object XMLDocument] #document 9