* xmlFormatError: * @err: the error * @channel: callback * @data: user data for callback * * Report a formatted error to a printf-like callback. * * This can result in a verbose multi-line report including additional * information from the parser context. * * Available since 2.13.0. */
| 413 | * Available since 2.13.0. |
| 414 | */ |
| 415 | void |
| 416 | xmlFormatError(const xmlError *err, xmlGenericErrorFunc channel, void *data) |
| 417 | { |
| 418 | const char *message; |
| 419 | const char *file; |
| 420 | int line; |
| 421 | int code; |
| 422 | int domain; |
| 423 | const xmlChar *name = NULL; |
| 424 | xmlNodePtr node; |
| 425 | xmlErrorLevel level; |
| 426 | xmlParserCtxtPtr ctxt = NULL; |
| 427 | xmlParserInputPtr input = NULL; |
| 428 | xmlParserInputPtr cur = NULL; |
| 429 | |
| 430 | if ((err == NULL) || (channel == NULL)) |
| 431 | return; |
| 432 | |
| 433 | message = err->message; |
| 434 | file = err->file; |
| 435 | line = err->line; |
| 436 | code = err->code; |
| 437 | domain = err->domain; |
| 438 | level = err->level; |
| 439 | node = err->node; |
| 440 | |
| 441 | if (code == XML_ERR_OK) |
| 442 | return; |
| 443 | |
| 444 | if ((domain == XML_FROM_PARSER) || (domain == XML_FROM_HTML) || |
| 445 | (domain == XML_FROM_DTD) || (domain == XML_FROM_NAMESPACE) || |
| 446 | (domain == XML_FROM_IO) || (domain == XML_FROM_VALID)) { |
| 447 | ctxt = err->ctxt; |
| 448 | } |
| 449 | |
| 450 | if ((node != NULL) && (node->type == XML_ELEMENT_NODE) && |
| 451 | (domain != XML_FROM_SCHEMASV)) |
| 452 | name = node->name; |
| 453 | |
| 454 | /* |
| 455 | * Maintain the compatibility with the legacy error handling |
| 456 | */ |
| 457 | if ((ctxt != NULL) && (ctxt->input != NULL)) { |
| 458 | input = ctxt->input; |
| 459 | if ((input->filename == NULL) && |
| 460 | (ctxt->inputNr > 1)) { |
| 461 | cur = input; |
| 462 | input = ctxt->inputTab[ctxt->inputNr - 2]; |
| 463 | } |
| 464 | if (input->filename) |
| 465 | channel(data, "%s:%d: ", input->filename, input->line); |
| 466 | else if ((line != 0) && (domain == XML_FROM_PARSER)) |
| 467 | channel(data, "Entity: line %d: ", input->line); |
| 468 | } else { |
| 469 | if (file != NULL) |
| 470 | channel(data, "%s:%d: ", file, line); |
| 471 | else if ((line != 0) && |
| 472 | ((domain == XML_FROM_PARSER) || (domain == XML_FROM_SCHEMASV)|| |