XML DOM parserfouten (Parser Errors)

Het parseError-object van Microsoft kan worden gebruikt om foutinformatie op te halen van de Microsoft XML-parser.

parseError-object

Bij het proberen een XML-document te openen, kan een parserfout (parser-error) optreden.

Met het parseError-object kunt u de foutcode, het regelnummer waarop de fout is opgetreden, etc. ophalen.

Opmerking:Het parseError-object behoort niet tot de W3C DOM-standaard!

Bestandsfout (File Error)

In de volgende code proberen we een niet bestaand bestand te laden en enkele fout-eigenschappen te tonen:

Read more about well-formed and valid XML in the middle.
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM")
xmlDoc.load("ksdjf.xml")
xmlDoc.load("note_error.xml")
document.write("Error code: " + xmlDoc.parseError.errorCode)
document.write("<br />Error reason: " + xmlDoc.parseError.reason)

document.write("<br />Error line: " + xmlDoc.parseError.line)

XML-fout (XML Error)

In de volgende code laden we de parser met een onjuist gevormde XML-document.

U kunt bij ons XML tutorial 中阅读更多有关形式良好且有效的 XML。)

Read more about well-formed and valid XML in the middle.
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load("note_error.xml")
document.write("Error code: " + xmlDoc.parseError.errorCode)
document.write("<br />Error reason: " + xmlDoc.parseError.reason)

document.write("<br />Error line: " + xmlDoc.parseError.line) TIY Or

Just view this XML file

Properties of the parseError object Attribute
Description errorCode
Return a long integer error code. reason
Return the string containing the cause of the error. line
Return a long integer representing the line number of the error. linepos
Return a long integer representing the line position of the error. srcText
Return the string containing the line that caused the error. url
Return the URL pointing to the loaded document. filepos