getNamedItem (DOMNamedNodeMap - JavaScript)

Gets a node by name.

Defined in

DOMNamedNodeMap

Syntax

getNamedItem(name:string) : DOMNode

Parameters Description
string The name of the node.
Return value Description
DOMNode The node or null. An invalid name 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 a named attribute for 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();
			var attr = map.getNamedItem("City");
			if(attr != null) {
				requestScope.y = requestScope.y +
				"\n\t\t" + attr.getNodeName() + " = " + attr.getNodeValue();
			} else {
				requestScope.y = requestScope.y +
				"\n\t\tCity is not set";
			}
		} 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
	element1
		City = London
	element2
		Has no attributes