xmlStructuredStop
function provides a simple R-level handler for errors
raised by the XML parser.
It collects the information provided by the XML parser and
raises an R error.
This is only used if NULL
is specified for the
error
argument of xmlTreeParse
,
xmlTreeParse
and htmlTreeParse
. The default is to use the function returned by a call to
xmlErrorCumulator
as the error handler.
This, as the name suggests, cumulates errors.
The idea is to catch each error and let the parser continue
and then report them all.
As each error is encountered, it is collected by the function.
If immediate
is TRUE
, the error is also reported on
the console.
When the parsing is complete and has failed, this function is
invoked again with a zero-length character vector as the
message (first argument) and then it raises an error.
This function will then raise an R condition of class class
.
xmlStructuredStop(msg, code, domain, line, col, level, filename,
class = "XMLError")
xmlErrorCumulator(class = "XMLParserErrorList", immediate = TRUE)
simpleError
.TRUE
errors are
displayed on the R console as they are encountered. Otherwise, the
errors are collected and displayed at the end of the XML parsing.stop
and so does not return a value.xmlTreeParse
xmlInternalTreeParse
htmlTreeParse
tryCatch( xmlTreeParse("<a><b></a>", asText = TRUE, error = NULL),
XMLError = function(e) {
cat("There was an error in the XML at line",
e$line, "column", e$col, "",
e$message, "")
})
Run the code above in your browser using DataLab