Entry
How do I use the method localName?
How do I use the method localName?
Apr 11th, 2005 01:56
Martin Honnen,
The method localName takes no argument and returns the local name part
if the XML object has a name.
Note that text nodes and comment nodes do not have a name thus for these
kind of XML objects null is returned.
Here are some examples:
var god = <god>Kibo</god>;
alert(god.localName()); // shows 'god'
var p = <xhtml:p xmlns:xhtml="http://www.w3.org/1999/xhtml">Kibology
for all.</xhtml:p>;
alert(p.localName()); // shows 'p'
var xlink = new Namespace('http://www.w3.org/1999/xlink');
var attributeNode = <home xmlns:xlink="http://www.w3.org/1999/xlink"
xlink:type="simple" />.@xlink::type;
alert(attributeNode.localName()); // shows 'type'
XML.ignoreProcessingInstructions = false;
var pi = <?process Kibology="on"?>;
alert(pi.localName()); // shows 'process'
var textNode = new XML('Kibology for all.');
alert(textNode.localName()); // shows 'null'
XML.ignoreComments = false;
var comment = <!-- All for Kibology. -->;
alert(comment.localName()); // shows 'null'