XML DOM createElementNS() विधि
वर्णन और उपयोग
createElementNS()
विधि नामस्पाद वाला एलिमेंट नोड बनाती है。
इस विधि से Element ऑब्जेक्ट वापस किया जाता है。
व्याकरण
createElementNS(एनएस,नाम)
पैरामीटर | वर्णन |
---|---|
एनएस | शब्द, एलिमेंट नोड के नामस्पाद नाम निर्धारित करता है。 |
नाम | शब्द, एलिमेंट नोड नाम निर्धारित करता है。 |
उदाहरण
नीचे कोड "books.xml" को xmlDoc में लोड करेगा और हर <book> एलिमेंट को एक नामस्पाद वाला एलिमेंट नोड जोड़ेगा:
वार एक्सएचटीएमएल = नया XMLHttpRequest(); xhttp.onreadystatechange = function() { यदि (इस.readyState == 4 && इस.status == 200) { माइफ़ंक्शन(इस); } }; xhttp.open("GET", "books.xml", true); xhttp.send(); फ़ंक्शन माइफ़ंक्शन(एक्सएमएल) { वार एक्स, य, ज, न, न्यूएल, न्यूटेक्स्ट, 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 + " संस्करण." + " नेमेस्पेस: " + z[i].namespaceURI + "<br>"; } document.getElementById("demo").innerHTML = txt; }