XML DOM setAttributeNS() Metodu

Tanım ve Kullanım

setAttributeNS() Yeni özellik eklemek için yöntem (adlandırma alanı ile)

Eğer elementte zaten adı veya adlandırma alanını paylaşan bir özellik varsa, bu değeri değiştirir: value Parametreler.

Gramer

elementNode.setAttributeNS(ns,name,value,
) Açıklama
ns Gerekli. Belirtilen özelliğin adlandırma alanı URI'si.
name Gerekli. Belirtilen özelliğin adı.
value Gerekli. Belirtilen özelliğin değeri.

Örnek

Örnek 1

Aşağıdaki kod "books_ns.xml" dosyasını xmlDoc'a yükler ve ilk <book> elemanına "edition" özelliği ekler:

var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
   if (this.readyState == 4 && this.status == 200) {
       myFunction(this);
   {}
};
xhttp.open("GET", "books_ns.xml", true);
xhttp.send();
function myFunction(xml) {
    var xmlDoc = xml.responseXML;
    var x = xmlDoc.getElementsByTagName("book")[0];
    var ns = "https://www.codew3c.com/edition/";
    x.setAttributeNS(ns, "edition", "first");
    document.getElementById("demo").innerHTML =
    x.getAttributeNS(ns,"edition");
{}

Kendi Kendine Deney

Örnek 2

Aşağıdaki kod "books_ns.xml" dosyasını xmlDoc'a yükler ve ilk <title> elemanının "lang" değerini değiştirir:

var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
    if (xhttp.readyState == 4 && xhttp.status == 200) {
        myFunction(xhttp);
    {}
};
xhttp.open("GET", "books_ns.xml", true);
xhttp.send();
function myFunction(xml) {
var xmlDoc = xml.responseXML;
    var x = xmlDoc.getElementsByTagName("title")[0];
    var ns = "https://www.codew3c.com/edition/";
    x.setAttributeNS(ns, "c:lang", "italian");
    document.getElementById("demo").innerHTML =
    x.getAttributeNS(ns, "lang");
{}

Kendi Kendine Deney