当前位置: 首页 > 网络学院 > XML相关教程 > XML DOM > getElementsByTagNameNS() 方法

XML DOM
DOM Attribute
DOM Text
DOM CDATA
DOM Comment
DOM HttpRequest
DOM ParseError
DOM 校验器
DOM 介绍
DOM 摘要
DOM 案例
DOM 节点树
DOM 访问节点树
DOM 节点信息
DOM 文档执行
DOM 节点导航

XML DOM 中的 getElementsByTagNameNS() 方法


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 451 ::
收藏到网摘: n/a

Definition and Usage
定义和用法

The getElementsByTagNameNS() method returns a NodeList of all elements with a specified name and namespace.
getElementsByTagNameNS() 方法返回了一组包含指定名称和命名空间的元素节点列表。

Syntax
语法

getElementsByTagNameNS(ns,name)

Parameter
元素
Description
描述
ns A string that specifies the namespace name to search for. The value "*" matches all tags
指定一个字符串,该字符串是用于指明需要搜索的命名空间名称的。使用通配符“*”将匹配所有的标签
name A string that specifies the tagname to search for. The value "*" matches all tags
指定一个字符串,该字符串是用于指明需要搜索的tagname[标签名称]的。使用通配符“*”将匹配所有的标签


In all examples, we will use the XML file books.xml, and the JavaScript function loadXMLDoc().
在所有案例中,我们将使用“book.xml”文件以及JavaScript 函数“loadXMLDoc()”。

Example
案例

The following code fragment adds an element node with a namespace to each <book> element:
下面的代码片断将一个元素节点及其命名空间添加到每个<book>元素中:

xmlDoc=loadXMLDoc("books.xml");
var x=xmlDoc.getElementsByTagName('book');
var newel,newtext;
for (i=0;i<x.length;i++) { newel=xmlDoc.createElementNS('p','edition'); newtext=xmlDoc.createTextNode('First'); newel.appendChild(newtext); x[i].appendChild(newel); }
//Output all titles and editions
var y=xmlDoc.getElementsByTagName("title");
var z=xmlDoc.getElementsByTagNameNS("p","edition");
for (i=0;i<y.length;i++) { document.write(y[i].childNodes[0].nodeValue); document.write(" - "); document.write(z[i].childNodes[0].nodeValue); document.write(" edition"); document.write("<br />"); }


Try-It-Yourself Demos
自我演示

createElementNS() - Create an element node with a namespace
createElementNS() - 创建一个包含命名空间的元素节点

评论 (0) All

登陆 | 还没注册?