پیشنهاد دوره:

XML DOM createComment() روش

تعریف و استفاده createComment()

روش ایجاد نود اظهار نظر.

این روش Comment جسد را برمی‌گرداند.

قانوندادهcreateComment(
) توضیح
داده زیرنویس، تعریف داده شده برای نود.

مثال

کد زیر "books.xml" را به xmlDoc بارگذاری می‌کند و نقاط اظهار نظر را به عناصر <book> اضافه می‌کند:

ویار xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = فانکشن() {
   اگر (this.readyState == 4 && this.status == 200) {
       myFunction(this);
   }
};
xhttp.open("GET", "books.xml", true);
xhttp.send();
فانکشن myFunction(xml) {
    ویار x, i, newComment, xmlDoc, txt;
    xmlDoc = xml.responseXML;
    txt = "";
    x = xmlDoc.getElementsByTagName("book");
    برای (i = 0; i < x.length; i++) {
        newComment = xmlDoc.createComment("Revised April 2008");
        x[i].appendChild(newComment);
    }
    برای (i = 0; i < x.length; i++) {
        txt += x[i].getElementsByTagName("title")[0].childNodes[0].nodeValue +
        " - " +
        x[i].lastChild.nodeValue + "<br>";
    }
    document.getElementById("demo").innerHTML = txt;
}

آزمایش کنید