Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

XML DOM getNamedItem() Method

XML DOM getNamedItem() Method


NamedNodeMap Object Reference NamedNodeMap object


Definition and Usage

The getNamedItem() method returns the specified node.

Syntax

getNamedItem(nodename)

Parameters Description
nodename The name of the node to retrieve.

Example

The following code snippet uses loadXMLDoc() to load "books.xml" Load into xmlDoc, loop through the elements and print the value of the category attribute:

Example

xmlDoc

=

loadXMLDoc

(

"

books.xml

"

)

;

x

=

xmlDoc

.

getElementsByTagName

(

'

book

'

)

;

for

(

i

=

0

;

i

<

x

.

length

;

i

++

)

{

att

=

x

.

item

(

i

)

.

attributes

.

getNamedItem

(

"

category

"

)

;

document

.

write

(

att

.

value

"


"

)

;

}

The code above will output:

COOKING

CHILDREN

WEB

WEB

Try it »


Try it Demos

getNamedItem() - Change the value of an item


NamedNodeMap Object Reference NamedNodeMap object