item (DOMNamedNodeMap - JavaScript)

Gets the node at a specified index.

Defined in

DOMNamedNodeMap

Syntax

item(index:int) : DOMNode

Parameters Description
index The index where 0 is the first node and getLength - 1 is the last index
Return value Description
DOMNode The node or null. A negative index causes an exception and a positive index that is out of range returns null.

Examples

This button gets the child nodes below the schema level of a DOM where requestScope.n is the location of a document in the database, and gets the attributes of each element.
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 element = schema.getFirstChild();
	while(element != null) {
		requestScope.y = requestScope.y +
			"\n\t" + element.getNodeName();
		if(element.hasAttributes()) {
			var map = element.getAttributes();
			for(var i=0; i< map.getLength(); i++) {
				var attr = map.item(i);
				requestScope.y = requestScope.y +
				"\n\t\t" + attr.getNodeName() + " = " + attr.getNodeValue();
			}
		} else {
			requestScope.y = requestScope.y +
				"\n\t\tHas no attributes";
		}
		element = element.getNextSibling();
	}
} else {
	requestScope.y = "No such document";
}
If the input XML to the DOM is as follows:
<schema0>
  <element0 City="Paris" Month="Mar">foo</element0>
  <element1 City="London">bar</element1>
  <element2>foobar</element2>
</schema0>
The display appears as follows:
Child nodes of schema0
	element0
		City = Paris
		Month = Mar
	element1
		City = London
	element2
		Has no attributes