XML DOM getElementsByTagName () method
Definition and Usage
getElementsByTagName () method returns a NodeList of all elements with the specified name.
grammar
getElementsByTagName(name)
参数 | 描述 |
---|---|
name | 字符串,规定要搜索的标签名。值 "*" 匹配所有的标签。 |
Examples
The following code fragment uses loadXMLDoc () to " the Books.xml " into xmlDoc and obtain the values of all <title> element:
Examples
xmlDoc=loadXMLDoc("books.xml");
x=xmlDoc.getElementsByTagName('title');
for (i=0;i<x.length;i++)
{
document.write(x[i].childNodes[0].nodeValue);
document.write("
");
}
x=xmlDoc.getElementsByTagName('title');
for (i=0;i<x.length;i++)
{
document.write(x[i].childNodes[0].nodeValue);
document.write("
");
}
Output:
Everyday Italian
Harry Potter
XQuery Kick Start
Learning XML
Harry Potter
XQuery Kick Start
Learning XML
try it"
Element object