Entry
How do I use the method name?
How do I use the method name?
Apr 11th, 2005 02:08
Martin Honnen,
The method name takes no argument and returns the qualified name (a
QName object) of the XML object it is called on or null if the object
has no name (as for text nodes and comment nodes).
In a string representation a qualified name is the concatenation of the
namespace URI, '::', and the local name e.g.
'http://example.com/2005/04/ns1::local-name'
Here are some examples:
var god = <god>Kibo</god>;
alert(god.name()); // shows 'god'
var p = <xhtml:p xmlns:xhtml="http://www.w3.org/1999/xhtml">Kibology
for all.</xhtml:p>;
alert(p.name()); // shows 'http://www.w3.org/1999/xhtml::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.name()); // shows 'http://www.w3.org/1999/xlink::type'
XML.ignoreProcessingInstructions = false;
var pi = <?process Kibology="on"?>;
alert(pi.name()); // shows 'process'
var textNode = new XML('Kibology for all.');
alert(textNode.name()); // shows 'null'
XML.ignoreComments = false;
var comment = <!-- All for Kibology. -->;
alert(comment.name()); // shows 'null'