1\name{xmlStructuredStop} 2\alias{xmlStructuredStop} 3\alias{xmlErrorCumulator} 4 5\title{Condition/error handler functions for XML parsing} 6\description{ 7 These functions provide basic error handling for the XML parser in 8 R. They also illustrate the basics which will allow others to 9 provide customized error handlers that make more use of the 10 information provided in each error reported. 11 12 The \code{xmlStructuredStop} function provides a simple R-level handler for errors 13 raised by the XML parser. 14 It collects the information provided by the XML parser and 15 raises an R error. 16 This is only used if \code{NULL} is specified for the 17 \code{error} argument of \code{\link{xmlTreeParse}}, 18 \code{\link{xmlTreeParse}} and \code{\link{htmlTreeParse}}. 19 20 The default is to use the function returned by a call to 21 \code{xmlErrorCumulator} as the error handler. 22 This, as the name suggests, cumulates errors. 23 The idea is to catch each error and let the parser continue 24 and then report them all. 25 As each error is encountered, it is collected by the function. 26 If \code{immediate} is \code{TRUE}, the error is also reported on 27 the console. 28 When the parsing is complete and has failed, this function is 29 invoked again with a zero-length character vector as the 30 message (first argument) and then it raises an error. 31 This function will then raise an R condition of class \code{class}. 32} 33\usage{ 34xmlStructuredStop(msg, code, domain, line, col, level, filename, 35 class = "XMLError") 36xmlErrorCumulator(class = "XMLParserErrorList", immediate = TRUE) 37} 38\arguments{ 39 \item{msg}{character string, the text of the message being reported} 40 \item{code}{ an integer code giving an identifier for the error (see 41 xmlerror.h) for the moment,} 42 \item{domain}{ an integer domain indicating in which "module" or part of the 43 parsing the error occurred, e.g. name space, parser, tree, xinclude, etc.} 44 \item{line}{ an integer giving the line number in the XML content 45 being processed corresponding to the error, } 46 \item{col}{ an integer giving the column position of the error, } 47 \item{level}{ an integer giving the severity of the error ranging from 1 to 3 in 48 increasing severity (warning, error, fatal),} 49 \item{filename}{character string, the name of the document being processed, i.e. its file name or 50 URL.} 51 \item{class}{ character vector, any classes to prepend to the class 52 attribute to make the error/condition. These are prepended to those 53 returned via \code{\link{simpleError}}.} 54 \item{immediate}{logical value, if \code{TRUE} errors are 55 displayed on the R console as they are encountered. Otherwise, the 56 errors are collected and displayed at the end of the XML parsing.} 57} 58 59\value{ 60 This calls \code{\link{stop}} and so does not return a value. 61} 62\references{libxml2 and its error handling facilities (\url{http://xmlsoft.org}} 63\author{ Duncan Temple Lang} 64 65\seealso{ 66 \code{\link{xmlTreeParse}} 67 \code{\link{xmlInternalTreeParse}} 68 \code{\link{htmlTreeParse}} 69} 70\examples{ 71 tryCatch( xmlTreeParse("<a><b></a>", asText = TRUE, error = NULL), 72 XMLError = function(e) { 73 cat("There was an error in the XML at line", 74 e$line, "column", e$col, "\n", 75 e$message, "\n") 76 }) 77} 78\keyword{IO } 79\keyword{programming} 80\concept{error handling} 81