XML DOM createElementNS() మార్గదర్శకం
నిర్వచనం మరియు ఉపయోగం
createElementNS()
ఈ మార్గదర్శకం నామకరణం కలిగిన ఎలమెంట్ నోడ్ సృష్టిస్తుంది。
ఈ మార్గదర్శకం Element అన్నికరణను అందిస్తుంది。
విధానం
createElementNS(ns,name)
పరామీతి | వివరణ |
---|---|
ns | స్ట్రింగ్,ఎలమెంట్ నోడ్ నామకరణం పేరును నిర్దేశిస్తుంది。 |
name | స్ట్రింగ్,ఎలమెంట్ నోడ్ పేరును నిర్దేశిస్తుంది。 |
ఉదాహరణ
ఈ కోడ్ "books.xml" ని xmlDoc లోకి లోడ్ చేయడానికి మరియు ప్రతి <book> ఎలమెంట్కు ఒక నామకరణం కలిగిన ఎలమెంట్ నోడ్ జోడించడానికి ఉపయోగించబడుతుంది:
var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && 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"); // నామకరణం మరియు టెక్స్ట్ నోడ్ తో ఎలమెంట్ నోడ్ సృష్టించండి for (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"); for (i = 0; i < y.length; i++) { txt += y[i].childNodes[0].nodeValue + " - " + z[i].childNodes[0].nodeValue + " edition." + " Namespace: " + z[i].namespaceURI + "
"; } document.getElementById("demo").innerHTML = txt; }