item (DOMNodeList - JavaScript)
Gets the node at a specified index.
Defined in
DOMNodeListSyntax
Parameters | Description |
---|---|
n |
The index of a node where 0 is the first node and getLength - 1 is the last node. |
Return value | Description |
---|---|
DOMNode |
The node at the specified index or null. A negative index returns node 0 if it exists. A positive index that is out of range returns null. |
Examples
This button gets the child nodes below the schema level of a DOM whererequestScope.n
is
the location of a document in the database.if (requestScope.n != null
&& requestScope.n < database.getDocumentCount()
&& requestScope.n >= 0) {
var dc = database.getAllDocuments();
var doc = dc.getDocumentArray()[requestScope.n];
var schema = doc.getFirstChild(); // get node below root
requestScope.y = "Child nodes of " + schema.getNodeName();
var list = schema.getChildNodes();
if(list.getLength() > 0) {
for(var i=0; i<list.getLength></list.getLength> {
requestScope.y = requestScope.y +
"\n\t" + list.item(i).getNodeName();
}
} else {
requestScope.y = requestScope.y + "\n\tNo elements";
}
} else {
requestScope.y = "No such document";
}
If the input XML to the DOM is as follows:
<schema0>
<element0>foo</element0>
<element1>bar</element1>
</schema0>
The display appears as follows:
Child nodes of schema0
element0
element1