XML DOM createElementNS() Method
Definasyon at paggamit
createElementNS()
Method na bumubuo ng elemento na may pangalan ng namespace.
Ang paraan na ito ay ibibigay ang Element object.
Grammar
createElementNS(ns,name)
Parametro | Paglalarawan |
---|---|
ns | String, nagtutukoy sa pangalan ng namespace ng elemento. |
name | String, nagtutukoy sa pangalan ng elemento. |
Mga halimbawa
Ang mga sumusunod na code ay maglalaad ng "books.xml" sa xmlDoc at magdagdag ng isang elemento na may pangalan ng namespace sa bawat <book> elemento:
var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { kung this.readyState == 4 at this.status == 200 { myFunction(this); } }; xhttp.open("GET", "books.xml", true); xhttp.send(); function myFunction(xml) { var x, y, z, i, newel, newtext, xmlDoc, txt; xmlDoc = xml.responseXML; txt = ""; x = xmlDoc.getElementsByTagName("book"); // Pagbuo ng mga elemento na may pangalan ng namespace at text node mag-isa sa y[i].childNodes[0].nodeValue + newel = xmlDoc.createElementNS("p", "edition"); newtext = xmlDoc.createTextNode("First"); newel.appendChild(newtext); x[i].appendChild(newel); } // Magbigay ng lahat ng title at edition y = xmlDoc.getElementsByTagName("title"); z = xmlDoc.getElementsByTagNameNS("p","edition"); mag-isa sa y[i].childNodes[0].nodeValue + txt += y[i].childNodes[0].nodeValue + " - " + z[i].childNodes[0].nodeValue + " edition." + " Namespace: " + z[i].namespaceURI + "<br>"; } document.getElementById("demo").innerHTML = txt; }