getNamedItemNS (DOMNamedNodeMap - JavaScript)

Gets a node by namespace and name.

Defined in

DOMNamedNodeMap

Syntax

getNamedItemNS(namespaceURI:string, localName:string) : DOMNode

Parameters Description
namespaceURI The URI of a node.
localName The local name of the node.
Return value Description
DOMNode The node or null. An invalid URI or local 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.getNamedItemNS("http://www.mynames.com", "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:
<s:schema0 xmlns:s="http://www.mynames.com">
  <s:element0 s:City="Paris" s:Month="Mar">foo</s:element0>
  <s:element1 s:City="London">bar</s:element1>
  <s:element2>foobar</s:element2>
</s:schema0>
The display appears as follows:
Child nodes of s:schema0
	s:element0
		s:City = Paris
	s:element1
		s:City = London
	s:element2
		Has no attributes