Metode lookupPrefix mengembalikan awalan terdekat yang ditentukan dalam namespace saat ini untuk URI namespace. Mengembalikan prefiks namespace terkait jika ditemukan atau null jika tidak ada yang ditemukan.
Sintaksis
Berikut ini adalah sintaks untuk penggunaan metode lookupPrefix .
nodeObject.lookupPrefix(DOMString namespaceURI)
S.No. | Parameter & Deskripsi |
1 |
namespaceURI
Berdasarkan awalan parameter ini dikembalikan. Ini adalah tipe DOMString . |
Metode ini mengembalikan awalan namespace terkait atau null jika tidak ada yang ditemukan.
Contoh
konten node_ns.xml seperti di bawah ini -
<?xml version = "1.0"?>
<Company>
<Employee xmlns:e = "http://www.tutorials.com/technical/" category = "technical">
<e:FirstName>Tanmay</e:FirstName>
<e:LastName>Patil</e:LastName>
<e:ContactNo>1234567890</e:ContactNo>
<e:Email>[email protected]</e:Email>
</Employee>
<Employee xmlns:n = "http://www.tutorials.com/non-technical/" category="non-technical">
<n:FirstName>Taniya</n:FirstName>
<n:LastName>Mishra</n:LastName>
<n:ContactNo>1234667898</n:ContactNo>
<n:Email>[email protected]</n:Email>
</Employee>
</Company>
Contoh berikut menunjukkan penggunaan metode lookupPrefix -
<!DOCTYPE html>
<html>
<head>
<script>
function loadXMLDoc(filename) {
if (window.XMLHttpRequest) {
xhttp = new XMLHttpRequest();
} else // code for IE5 and IE6 {
xhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET",filename,false);
xhttp.send();
return xhttp.responseXML;
}
</script>
</head>
<body>
<script>
xmlDoc = loadXMLDoc("/dom/node_ns.xml");
y = xmlDoc.getElementsByTagName("Employee")[0];
document.write("lookupPrefix is : ")
document.write(y.lookupPrefix("http://www.tutorials.com/technical/"));
</script>
</body>
</html>
Eksekusi
Simpan file ini sebagai nodemethod_lookupprefix.htm di jalur server (file ini dan node_ns.xml harus berada di jalur yang sama di server Anda). Kami akan mendapatkan output seperti yang ditunjukkan di bawah ini -
lookupPrefix is : e