Đoạn mã sau tải "books. xml" vào xmlDoc, hiển thị tên nút, giá trị nút và loại nút của thuộc tính danh mục
var xhttp = new XMLHttpRequest[];
xhttp. onreadystatechange = function[] {
if [this. readyState == 4 && cái này. status == 200] {
myFunction[this];
}
};
xhttp. open["NHẬN", "sách. xml", true];
xhttp. gửi[];
function myFunction[xml] {
var x, i, xmlDoc, txt;
xmlDoc = xml. responseXML;
txt = "";
x = xmlDoc. getElementsByTagName['book'];
for [i = 0; i < x. chiều dài; . mặt hàng]. thuộc tính[0]. nodeName +
txt += x.item[i].attributes[0].nodeName +
" = " +
x. mặt hàng]. thuộc tính[0]. nodeValue +
" [nodetype. " + x. mặt hàng]. thuộc tính[0]. nodeType + "]" + "
";
}
tài liệu. getElementById["bản trình diễn"]. innerHTML = txt;
}
đầu ra
category = nấu ăn [nodetype. 2]
category = children [nodetype. 2]
category = web [nodetype. 2]
category = web [nodetype. 2]
Định nghĩa và cách sử dụng
Thuộc tính nodeValue đặt hoặc trả về giá trị của nút, tùy thuộc vào loại nút
cú pháp
❮ Đối tượng AttrNhưng đối tượng duy nhất của tất cả các thuộc tính và đó không phải là thứ tôi muốn có và tôi muốn nhận giá trị
DOMElement Object
[
[tagName] => p
[schemaTypeInfo] =>
[nodeName] => p
[nodeValue] =>
Go Back
[nodeType] => 1
[parentNode] => [object value omitted]
[childNodes] => [object value omitted]
[firstChild] => [object value omitted]
[lastChild] => [object value omitted]
[previousSibling] => [object value omitted]
[nextSibling] => [object value omitted]
[attributes] => [object value omitted]
[ownerDocument] => [object value omitted]
[namespaceURI] =>
[prefix] =>
[localName] => p
[baseURI] =>
[textContent] =>
Go Back
]
1,DOMElement Object
[
[tagName] => p
[schemaTypeInfo] =>
[nodeName] => p
[nodeValue] =>
Go Back
[nodeType] => 1
[parentNode] => [object value omitted]
[childNodes] => [object value omitted]
[firstChild] => [object value omitted]
[lastChild] => [object value omitted]
[previousSibling] => [object value omitted]
[nextSibling] => [object value omitted]
[attributes] => [object value omitted]
[ownerDocument] => [object value omitted]
[namespaceURI] =>
[prefix] =>
[localName] => p
[baseURI] =>
[textContent] =>
Go Back
]
2 và_______03 từ HTML nèvợ tôi