XML DOM createCDATASection() روش

تعریف و استفاده

createCDATASection() این روش یک گره CDATA section ایجاد می‌کند.

این روش یک شیء CDATASection را برمی‌گرداند.

منطق

createCDATASection(داده)
پارامتر توضیح
داده زبان، داده‌های گره را مشخص می‌کند.

مثال

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

واریاابل xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
   اگر (this.readyState == 4 && this.status == 200) {
       myFunction(this);
   {}
};
xhttp.open("GET", "books.xml", true);
xhttp.send();
دستور کار myFunction(xml) {
    واریاابل x, i, newCDATA, newtext, xmlDoc, txt;
    xmlDoc = xml.responseXML;
    txt = "";
    x = xmlDoc.getElementsByTagName("book");
    newtext = "Special Offer & Book Sale";
    برای (i = 0; i < x.length; i++) {
        newCDATA = xmlDoc.createCDATASection(newtext);
        x[i].appendChild(newCDATA);
    {}
    برای (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;
{}

آپ خود سجاوٹ کریں