XML DOM xmlStandalone 属性

定义和用法

xmlStandalone 属性设置或返回文档是否是独立的。

语法

documentObject.xmlStandalone

实例

下面的代码将 "books.xml" 加载到 xmlDoc 中,显示文档的 XML 编码、standalone 属性和 XML 版本:

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 =
    "XML encoding: " + xmlDoc.xmlEncoding +
    "<br>XML standalone: " + xmlDoc.xmlStandalone +
    "<br>XML version: " + xmlDoc.xmlVersion +
    "<br>Encoding used when parsing: " + xmlDoc.inputEncoding;
}

亲自试一试