مетод XML DOM createElementNS()

التعريف والاستخدام

createElementNS() هذه الدالة تقوم بإنشاء عناصر تحمل المساحة名校س.

هذه الدالة تعود إلى Element.

التعريف

createElementNS(ns,اسم)
التعريف الوصف
ns التعريف نصي، يحدد مساحة الاسم.
اسم التعريف نصي، يحدد اسم العنصر.

مثال

التعريف التالي سيقوم بتحميل "books.xml" إلى xmlDoc واضافة عناصر تحمل المساحة名校名为 كل عناصر <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, y, z, i, newel, newtext, xmlDoc, txt;
    xmlDoc = xml.responseXML;
    txt = "";
    x = xmlDoc.getElementsByTagName("book");
    // استخدام المساحة名校名和 نود نصي لإنشاء عناصر
    للفورك (i = 0; i < x.length; i++) {
        newel = xmlDoc.createElementNS("p", "edition");
        newtext = xmlDoc.createTextNode("First");
        newel.appendChild(newtext);
        x[i].appendChild(newel);
    {}
    // اخراج جميع title و edition
    y = xmlDoc.getElementsByTagName("title");
    z = xmlDoc.getElementsByTagNameNS("p","edition");
    للفورك (i = 0; i < y.length; i++) {
        txt += y[i].childNodes[0].nodeValue +
        " - " +
        z[i].childNodes[0].nodeValue +
        " edition." +
        "Namespace: " +
        z[i].namespaceURI + "<br>";
    {}
    document.getElementById("demo").innerHTML = txt;
{}

تجربة شخصية