XML DOM getNamedItem() Method
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
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