XML DOM オーナードキュメント属性

定義と用法

ownerDocument プロパティは、ノードが属するルート要素を返しますDocument オブジェクト)。

文法:

attrObject.ownerDocument

インスタンス

すべての例では、以下の XML ファイルを使用します: books.xml、および JavaScript 関数 loadXMLDoc()

以下のコードスニペットは、XML ドキュメント内の最初の category 属性ノードのルート要素を返します:

xmlDoc=loadXMLDoc("/example/xdom/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