Proprietà prefix del DOM XML
Definizione e uso
prefix
L'attributo restituisce il prefisso del namespace dell'elemento selezionato.
Se il nodo selezionato non è un elemento o un attributo, questa proprietà restituisce sempre NULL.
Sintassi
elementNode.prefix
Esempio
Il codice seguente carica "books_ns.xml" nel xmlDoc e recupera il prefisso del namespace dal primo elemento <title>:
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("title")[0]; document.getElementById("demo").innerHTML = x.prefix; }