XML DOM nodeName అనునాత

నిర్వచనం మరియు వినియోగం

nodeName అంశం రకం ఆధారంగా అంశం పేరు తిరిగి ఇస్తుంది.

విధానం

documentObject.nodeName

ఇన్స్టాన్స్

ఉదాహరణ 1

ఈ కోడు "books.xml" ను xmlDoc లోకి లోడ్ చేస్తుంది మరియు పునఃకరణ పునఃకరణ యొక్క నోడెమెన్ మరియు నోడెటాప్ ప్రదర్శిస్తుంది:

var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
   if (this.readyState == 4 && this.status == 200) {
       myFunction(this);
   }
};
xhttp.open("GET", "books.xml", true);
xhttp.send();
function myFunction(xml) {
    var xmlDoc = xml.responseXML;
    document.getElementById("demo").innerHTML =
    "నోడెమెన్: " + xmlDoc.nodeName +
    " (నోడెటాప్: " + xmlDoc.nodeType + ")";
}

亲自试一试

ఉదాహరణ 2

ప్రదర్శించండి అన్ని ఎలమెంట్స్ యొక్క nodeName మరియు nodeValue:

var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
        myFunction(this);
    }
};
xhttp.open("GET", "books.xml", true);
xhttp.send();
function myFunction(xml) {
    var x, y, i, xmlDoc, txt;
    xmlDoc = xml.responseXML;
    txt = "";
    x = xmlDoc.documentElement;
    y = xmlDoc.documentElement.childNodes;
    for(i = 0; i < y.length; i++) {
        if (y[i].nodeType != 3) {
            txt += "నోడెమెన్: " + y[i].nodeName +
            " (విలువ: " + y[i].childNodes[0].nodeValue + ")<br>";
        }
        for(z = 0; z < y[i].childNodes.length; z++) {
            if (y[i].childNodes[z].nodeType != 3) {
                txt += "నోడెమెన్: " + y[i].childNodes[z].nodeName +
                " (విలువ: " + y[i].childNodes[z].childNodes[0].nodeValue + ")<br>";
            }
        }
    }
    document.getElementById("demo").innerHTML = 
    "నోడెమెన్: " + xmlDoc.nodeName +
    " (value: " + xmlDoc.childNodes[0].nodeValue + ")<br>" +
    "Nodename: " + x.nodeName + 
    " (value: " + x.childNodes[0].nodeValue + ")<br>" +
    txt;
}

亲自试一试