XML DOM length 属性

ການສະແດງ ແລະ ການນໍາໃຊ້

length ຈຳນວນຂອງອົງການຕົວເຫມືອງທີ່ຢູ່ໃນ NamedNodeMap.

ສານສັນຍາ

nodemapObject.length

ຄວາມນິຍົມ

ຄຳວັດຈຳນວນ 1

ລະຫັດການລະບຸ: "books.xml" ກຳລັງບັນທຶກໃນ xmlDoc ແລະການເອົາຈຳນວນຂອງການລະບຸ <book> ທີ່ທໍາອິດ:

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");
    document.getElementById("demo").innerHTML =
    "Number of attributes in the first book element: " +
    x.item(0).attributes.length;
}

ສວດການສຳລັບຕົວເອງ

ຄຳວັດຈຳນວນ 2

ການກັບຄືນຈຳນວນຂອງຕົວເຫມືອງໃນລາຍການ:

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("title");
    document.getElementById("demo").innerHTML =
    "Number of title elements: " + x.length;
}

ສວດການສຳລັບຕົວເອງ

ຄຳວັດຈຳນວນ 3

ການແຜ່ກະຈາຍຕົວເຫມືອງທີ່ຢູ່ໃນລາຍການຂອງຕົວເຫມືອງ:

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, xmlDoc, txt;
    xmlDoc = xml.responseXML;
    txt = "";
    x = xmlDoc.getElementsByTagName('title');
    for (i = 0 ; i <x.length; i++) {
        txt += x[i].childNodes[0].nodeValue + "<br>";
    }
    document.getElementById("demo").innerHTML = txt;
}

ສວດການສຳລັບຕົວເອງ