XML DOM attribute అట్రిబ్యూట్

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

attribute అట్రిబ్యూట్ వారు NamedNodeMap (అట్రిబ్యూట్ జాబితా) తిరిగి చెప్పుతారు కలిగి ఉన్నారు పెరుగుతుంది ఎందుకంటే ఎంపికచేసిన నోడ్.

ఎందుకంటే ఎంపికచేసిన నోడ్ ఎలిమెంట్ కాది అయితే ఈ అట్రిబ్యూట్ వారు NULL తిరిగి చెప్పుతారు.

హింసాజనకం ప్రత్యామ్నాయం ప్రారంభం చేయండి:ఈ అట్రిబ్యూట్ మాత్రమే ఎలిమెంట్ నోడ్స్ కు వర్తిస్తుంది.

సంకేతాలు

elementNode.attributes

ఉదాహరణ

ఈ కోడు "books.xml" ని xmlDoc లోకి లోడ్ చేస్తుంది మరియు "books.xml" లో మొదటి <title> మెటాడాటా లో అట్రిబ్యూట్ ల సంఖ్యను పొందుతుంది:

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;
    var x = xmlDoc.getElementsByTagName("book")[0].attributes;
    document.getElementById("demo").innerHTML =
    x.length;
}

亲自试一试

ఉదాహరణ

2 ఈ కోడు "books.xml" ని xmlDoc లోకి లోడ్ చేస్తుంది మరియు మొదటి <book> మెటాడాటా లో "category" అట్రిబ్యూట్ విలువను పొందుతుంది:
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, i, att, xmlDoc, txt;
    xmlDoc = xml.responseXML;
    txt = "";
    x = xmlDoc.getElementsByTagName('book');
    for (i = 0; i < x.length; i++) {
        att = x.item(i).attributes.getNamedItem("category");
        txt += att.value + "<br>";
    }
    document.getElementById("demo").innerHTML = txt;
}

亲自试一试