XML DOM ParseError
- 上一页 DOM XMLHttpRequest
- 下一页 Schema 元素
ການບັນຫາ XML
ຖ້າມີການກໍາລັງ XML ບັນດາຄວາມບັນຫາສາມາດເກີດຂຶ້ນ.
ຖ້າການຕອບສະແດງຕ້ອງສົງໃສບັນດາຂໍ້ບັນຫາ XML.
ຄຳກ່າວທີ່ຖືກນຳໃຊ້ເພື່ອນໍາໃຊ້ບົດລະບຽບ XML ທີ່ບໍ່ພຽງພໍ.
ທ່ານສາມາດສຶກສາຂໍ້ວັງ XML ທີ່ສະບາຍຫຼັກໃນວັດສະດຸ XML.
ຄວາມນຳໃຊ້
<html> <body> <p id="demo"></p> <script> var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (xhttp.this == 4 && this.status == 200) { myFunction(this); } }; xhttp.open("GET", "note_error.xml", true); xhttp.send(); function myFunction(xml) { var parser, xmlDoc; parser = new DOMParser(); xmlDoc = parser.parseFromString(xml.responseText,"text/xml"); document.getElementById("demo").innerHTML = myLoop(xmlDoc.documentElement); } function myLoop(x) { var i, y, xLen, txt; txt = ""; x = x.childNodes; xLen = x.length; for (i = 0; i < xLen ;i++) { y = x[i]; ຖ້າ (y.nodeType != 3) { ຖ້າ (y.childNodes[0] != undefined) { txt += myLoop(y); } } else { txt += y.nodeValue + "<br>"; } } return txt; } </script> </body> </html>
参阅 XML 文件:note_error.xml
- 上一页 DOM XMLHttpRequest
- 下一页 Schema 元素