Atribut xmlEncoding DOM XML

Definisi dan penggunaan

xmlEncoding Atribut mengembalikan pengkodean dokumen.

Syarat

documentObject.xmlEncoding

Contoh

Kode berikut akan mengambil "books.xml" ke xmlDoc, menampilkan pengkodean XML, atribut standalone dan versi 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 =
    "Pengkodean XML: " + xmlDoc.xmlEncoding +
    "<br>XML 独立: " + xmlDoc.xmlStandalone +
    "<br>XML 版本: " + xmlDoc.xmlVersion +
    "<br>解析时使用的编码: " + xmlDoc.inputEncoding;
}

亲自试一试