DOM ParseError object
XML DOM Parse Error Object
Microsoft's parseError object can be used to retrieve error information from Microsoft's XML parser.
To see how Firefox handles parser errors, see the next page of this tutorial.
parseError Object
A parser-error may occur when you try to open an XML document.
With this parseError object, you can retrieve the error code, error text, line that caused the error, and so on.
Note: The parseError object does not belong to the W3C DOM standard!
File Error
In the following code, we will try to load a file that does not exist and display certain error attributes:
Instance
<html> <body> <script> var xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async=false; xmlDoc.load("ksdjf.xml"); document.write("Error code: " + xmlDoc.parseError.errorCode); document.write("<br>Error reason: " + xmlDoc.parseError.reason); document.write("<br>Error line: " + xmlDoc.parseError.line); </script> </body> </html>
Run Instance»
Click the "Run Instance" button to view the online instance
XML Error
In the following code, we ask the parser to load a malformed XML document.
(You can read more about well-formed and valid XML in our XML tutorial.)
Example
<html> <body> <script> 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); </script> </body> </html>
Run instance»
Click the "Run instance" button to view the online instance
View the XML file: note_error.xml
parseError object properties
Property | Description |
---|---|
errorCode | Returns a long integer error code. |
reason | Returns a string containing the reason for the error. |
line | Returns a long integer representing the wrong line number. |
linepos | Returns a long integer representing the error line position. |
srcText | Returns a string containing the line that caused the error. |
url | Returns the URL pointing to the loaded document. |
filepos | Returns the wrong long file position. |