javascript Node localName, namespaceURI, prefix
| localName, namespaceURI, prefix | NN 6 IE n/a DOM 2 |
| Read-only | |
|
These three properties apply primarily to XML document elements with tags that are defined with the help of XML namespaces. A simplified example of such a document follows: <?xml version="1.0" encoding="ISO-8859-1"> <results xmlns:libBook="http://catalog.umv.edu/schema"> <libBook:title libBook:rareBooks="true">De Principia</libBook:title> </results>? |
|
The properties reveal details about the element's naming characteristics. A localName is the equivalent of the nodeName property of the element, that is, the tag name within the scope of the entire document, even if the tag name is reused by another element originating from another namespace. The prefix, however, links the element with a prefix name that is normally defined with an xmlns attribute of a container in the XML document. This helps your script identify the namespace to which the element is associated. A further binding is revealed through the namespaceURI property, which returns the URI string assigned to the xmlns attribute of a container element. Although all three properties belong to the Node object, their values are null (or, rather, should be null, but in Netscape 6 are empty strings) for node types other than element and attribute nodes. |
|
| Example | |
var allTitles = document.getElementsByTagName("title");
for (var i = 0; i < allTitles.length; i++) {
if (allTitles[i].prefix == "libBook" &&
allTitles[i].namespaceURI.indexOf("catalog.umv.edu") != -1) {
// process title elements from the desired namespace here
}
}
|
|
| Value | |
Strings. |
|
| Default | |
For localName, the element's tag name. For others, an empty string. |
|
