在所有的例子中,我们将使用 XML 文件 books.xml,以及 JavaScript 函数 loadXMLDoc()。
下面的代码片段返回 XML 文档中第一个 category 属性节点的根元素:
</>code
- 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
);
以上代码的输出:
</>code
- [object XMLDocument]
- #document
- 9
如对本文有疑问,请提交到交流论坛,广大热心网友会为你解答!! 点击进入论坛