XML DOM createCDATASection() method
تعريف ووظيفة
createCDATASection()
يُستخدم هذا الطريقة لإنشاء علامة CDATA section.
هذه الطريقة تعود بـ CDATASection object.
النصوص
إنشاء علامة CDATA sectionبيانات)
الم参数 | وصف |
---|---|
بيانات | تعريف النصوص في العقد. |
مثال
الخطوات التالية ستجلب ملف "books.xml" إلى xmlDoc وتضيف علامة CDATA section إلى علامة <book>:
إنشاء متغير XMLHttpRequest جديد: var xhttp = new XMLHttpRequest(); تعيين الاستجابة للحدث.onreadystatechange = function() { إذا كان هذا جاهزًا (this.readyState == 4) وتم تنفيذ العملية بنجاح (this.status == 200) { myFunction(this); } }; xhttp.open("GET", "books.xml", true); xhttp.send(); وظيفة myFunction(xml) { تعريف المتغيرات: var x, i, newCDATA, newtext, xmlDoc, txt; xmlDoc = xml.responseXML; txt = ""; x = xmlDoc.getElementsByTagName("book"); newtext = "عرض خاص & بيع كتب"; للحصول على النصوص التالية: x[i].getElementsByTagName("title")[0].childNodes[0].nodeValue + newCDATA = xmlDoc.createCDATASection(newtext); x[i].appendChild(newCDATA); } للحصول على النصوص التالية: x[i].getElementsByTagName("title")[0].childNodes[0].nodeValue + txt += x[i].getElementsByTagName("title")[0].childNodes[0].nodeValue + " - " + x[i].lastChild.nodeValue + "<br>"; } document.getElementById("demo").innerHTML = txt; }