什么是nodeType属性javascript xml?

时间:2017-02-18 12:22:46

标签: javascript xml

https://www.w3schools.com/xml/tryit.asp?filename=try_dom_root

为什么要返回号码?

<!DOCTYPE html>
<html>
<body>

<p id="demo"></p>

<script>
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
        myFunction(this);
    }
};
xhttp.open("GET", "books.xml", true);
xhttp.send();

function myFunction(xml) {
    var xmlDoc = xml.responseXML;
    document.getElementById("demo").innerHTML =
    xmlDoc.documentElement.nodeName + "<br>" +
    xmlDoc.documentElement.nodeType;
}
</script>

</body>
</html>

一些垃圾文本,一些垃圾文本,一些垃圾文本

1 个答案:

答案 0 :(得分:0)

  

为什么要返回号码?

因为那是how it's defined

  类型为nodeType

unsigned short,只读

     

表示基础对象类型的代码,如上所述。

...“上面定义的”是指Node interface的类型常量:

// NodeType
const unsigned short      ELEMENT_NODE                   = 1;
const unsigned short      ATTRIBUTE_NODE                 = 2;
const unsigned short      TEXT_NODE                      = 3;
const unsigned short      CDATA_SECTION_NODE             = 4;
const unsigned short      ENTITY_REFERENCE_NODE          = 5;
const unsigned short      ENTITY_NODE                    = 6;
const unsigned short      PROCESSING_INSTRUCTION_NODE    = 7;
const unsigned short      COMMENT_NODE                   = 8;
const unsigned short      DOCUMENT_NODE                  = 9;
const unsigned short      DOCUMENT_TYPE_NODE             = 10;
const unsigned short      DOCUMENT_FRAGMENT_NODE         = 11;
const unsigned short      NOTATION_NODE                  = 12;