XML DOM createCDATASection() विधि

वर्णन और उपयोग

createCDATASection() विधि एक CDATA section नोड को बनाती है。

यह विधि CDATASection ऑब्जेक्ट वापस देती है。

व्याकरण

createCDATASection(डाटा)
पैरामीटर वर्णन
डाटा इंटरवेल्यू, नोड डाटा को निर्धारित करता है。

उदाहरण

नीचे का कोड "books.xml" को xmlDoc में लोड करता है और <book> एलीमेंट में CDATA section नोड को जोड़ता है:

वार (xhttp = new XMLHttpRequest());
xhttp.onreadystatechange = function() {
   यदि (this.readyState == 4 && this.status == 200) {
       माइफ़ून्शन (इस);
   }
};
xhttp.open("GET", "books.xml", true);
xhttp.send();
फ़ंक्शन माइफ़ून्शन (xml) {
    वार (xhttp = new XMLHttpRequest());
    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;
}

स्वयं प्रयोग करें