Index: generic/tcldom.c ================================================================== --- generic/tcldom.c +++ generic/tcldom.c @@ -6546,11 +6546,11 @@ useForeignDTD, paramEntityParsing, interp, &status); if (doc == NULL) { - char s[50]; + char s[50], linenr[50], columnnr[50]; long byteIndex, i; switch (status) { case TCL_BREAK: /* Abort of parsing by the application */ @@ -6557,22 +6557,22 @@ Tcl_ResetResult(interp); XML_ParserFree(parser); return TCL_OK; default: interpResult = Tcl_GetStringResult(interp); - sprintf(s, "%ld", XML_GetCurrentLineNumber(parser)); + sprintf(linenr, "%ld", XML_GetCurrentLineNumber(parser)); + sprintf(columnnr, "%ld", XML_GetCurrentColumnNumber(parser)); if (interpResult[0] == '\0') { /* If the interp result isn't empty, then there was an error in an enternal entity and the interp result has already the error msg. If we don't got a document, but interp result is empty, the error occured in the main document and we build the error msg as follows. */ Tcl_AppendResult(interp, "error \"", XML_ErrorString(XML_GetErrorCode(parser)), - "\" at line ", s, " character ", NULL); - sprintf(s, "%ld", XML_GetCurrentColumnNumber(parser)); - Tcl_AppendResult(interp, s, NULL); + "\" at line ", linenr, " character ", + columnnr, NULL); byteIndex = XML_GetCurrentByteIndex(parser); if ((byteIndex != -1) && (chan == NULL)) { Tcl_AppendResult(interp, "\n\"", NULL); s[1] = '\0'; for (i=-20; i < 40; i++) { @@ -6588,10 +6588,15 @@ } } } Tcl_AppendResult(interp, "\"",NULL); } + sprintf(s, "%d", XML_GetErrorCode(parser)); + Tcl_SetErrorCode(interp, "TDOM", "NOTWELLFORMED", linenr, + columnnr, s, + XML_ErrorString(XML_GetErrorCode(parser)), + NULL); } else { if (status == TCL_OK) { /* For tcl errors (in -externalentitycommand or * feedback callback) we leave the error msg in * the interpreter alone. If there wasn't a tcl @@ -6598,13 +6603,13 @@ * error, there was a parsing error. Because the * interp has already an error msg, that parsing * error was in an external entity. Therefore, we * just add the place of the referencing entity in * the mail document.*/ - Tcl_AppendResult(interp, ", referenced at line ", s, NULL); - sprintf(s, "%ld", XML_GetCurrentColumnNumber(parser)); - Tcl_AppendResult(interp, " character ", s, NULL); + Tcl_AppendResult(interp, ", referenced at line ", + linenr, " character ", columnnr, + NULL); } } XML_ParserFree(parser); return TCL_ERROR; } Index: tests/dom.test ================================================================== --- tests/dom.test +++ tests/dom.test @@ -571,10 +571,15 @@ test dom-2.34 {XML prefix declaration with empty namespace} { catch {dom parse {}} errMsg set errMsg } {Missing URI in Namespace declaration, referenced at line 1 character 22} + +test dom-2.34 {errorCode after XML parsing error} { + catch {dom parse "foo"} errMsg catchResult + set errorCode +} {TDOM NOTWELLFORMED 1 0 2 {syntax error}} test dom-3.1 {isName} { dom isName ":foo" } {1}