XML DOM documentURI 屬性

定義和用法

documentURI 屬性設置或返回文檔的位置。

語法

documentObject.documentURI

實例

下面的代碼將 "books.xml" 加載到 xmlDoc 中,并顯示 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 =
    "Document location: " + xmlDoc.documentURI;
}

親自試一試