Phương thức tra cứu XML DOMPrefix()
❮ Đối tượng phần tử
Ví dụ
Đoạn mã sau tải " books_ns.xml " vào xmlDoc và tìm tiền tố cho URI vùng tên đã cho:
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];
document.getElementById("demo").innerHTML =
x.lookupPrefix("https://www.example.com.vn/children/");
}
Đầu ra:
c
Hãy tự mình thử »Định nghĩa và cách sử dụng
Phương thức lookupPrefix() trả về tiền tố khớp với URI vùng tên đã chỉ định trên nút hiện tại.
Cú pháp
elementNode.lookupPrefix(URI)
Parameter | Description |
---|---|
URI | Required. The namespace URI for the prefix to find |
❮ Đối tượng phần tử