XML DOM xmlVersion 屬性

定義和用法

xmlVersion 屬性設置或返回文檔的 XML 版本。

語法

documentObject.xmlVersion

實例

下面的代碼將 "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;
}

親自試一試