XML DOM item() Method
NamedNodeMap object
Definition and Usage
The item() method returns the node with the specified index in a node list.
Syntax
item(index)
| Parameters | Description |
|---|---|
| index | Index. |
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
item() - Loop through the items in a node list
getNamedItem() - Change the value of an item
NamedNodeMap object