XML DOM substringData() পদ্ধতি

সংজ্ঞা ও ব্যবহার

substringData() পদ্ধতি মন্তব্য নোড থেকে শব্দ পাওয়া হবে。

সংজ্ঞা

substringData(start,length)
পারামিটার বর্ণনা
start প্রয়োজনীয়
length প্রয়োজনীয়

একটি উদাহরণ

নিচের কোড "books_comment.xml"-কে xmlDoc-এ লোড করে, এবং প্রথম মন্তব্য নোড থেকে "(Hardcover)" শব্দকে পাওয়া হবে:

var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
   if (this.readyState == 4 && this.status == 200) {
       myFunction(this);
   }
};
xhttp.open("GET", "books_comment.xml", true);
xhttp.send();
function myFunction(xml) {
    var x, i, y, txt, xmlDoc;
    xmlDoc = xml.responseXML;
    txt = "";
    x = xmlDoc.getElementsByTagName("book")[0].childNodes;
    for (i = 0; i < x.length; i++) {
    // মন্তব্য নোড এবং কেবল এটি প্রক্রিয়াকরণ করা হবে
        if (x[i].nodeType == 8) {
            y = x[i].substringData(33, 11);
            txt += y + "<br>";
        }
    }
    document.getElementById("demo").innerHTML = txt;
}

亲自试一试

在上面的例子中,我们用了循环和 if 测试语句,来确保我们只处理注释节点。注释节点的节点类型为 8。