HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
When trying to open an XML document, a parser-error may occur
When trying to open an XML document, a parser-error may occur.
If the parser encounters an error, it may load an XML document containing the error description.
The code example below tries to load an XML document that is not well-formed.
You can read more about well-formed XML in XML Syntax.
<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];
if (y.nodeType != 3) {
if (y.childNodes[0]
!= undefined) {
txt += myLoop(y);
}
} else {
txt += y.nodeValue +
"<br>";
}
}
return txt;
}
</script>
</body>
</html>