File: xmlStopParser.Rd

package info (click to toggle)
r-cran-xml 3.99-0.19-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,688 kB
  • sloc: ansic: 6,659; xml: 2,890; asm: 486; sh: 12; makefile: 2
file content (70 lines) | stat: -rw-r--r-- 2,353 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
\name{xmlStopParser}
\alias{xmlStopParser}
\title{Terminate an XML parser}
\description{
  This function allows an R-level function to terminate an
  XML parser before it completes the processing of the XML content.
  This might be useful, for example, in event-driven parsing
  with \code{\link{xmlEventParse}}  when we want 
  to read through an XML file until we find a record of interest.
  Then, having retrieved the necessary information, we want to 
  terminate the parsing rather than let it pointlessly continue.
  Instead of raising an error in our handler function, we can call
  \code{xmlStopParser} and return. The parser will then take control
  again and terminate and return back to the original R function from
  which it was invoked. 

 The only argument to this function is a reference to internal C-level 
  which identifies the parser.   This is passed by the R-XML parser
  mechanism to a function invoked by the parser if that function
  inherits (in the S3 sense) from the class \code{XMLParserContextFunction}.
}
\usage{
xmlStopParser(parser)
}
%- maybe also 'usage' for other objects documented here.
\arguments{
  \item{parser}{ an object of class \code{XMLParserContext}
     which must have been obtained by via an
  \code{XMLParserContextFunction} function
    called by the parser. This is just a handler function whose class
    includes \code{XMLParserContextFunction}
  }
}

\value{
   \code{TRUE} if it succeeded and an error is raised 
  if the \code{parser} object  is not valid.
}
\references{libxml2 \url{http://xmlsoft.org}}
\author{Duncan Temple Lang}

\seealso{ 
 \code{\link{xmlEventParse}}
}
\examples{

  ############################################
  # Stopping the parser mid-way and an example of using XMLParserContextFunction.

  startElement =
  function(ctxt, name, attrs, ...)  {
    print(ctxt)
      print(name)
      if(name == "rewriteURI") {
           cat("Terminating parser\n")
	   xmlStopParser(ctxt)
      }
  }
  class(startElement) = "XMLParserContextFunction"  
  endElement =
  function(name, ...) 
    cat("ending", name, "\n")

  fileName = system.file("exampleData", "catalog.xml", package = "XML")
  xmlEventParse(fileName, handlers = list(startElement = startElement, endElement = endElement))
}
\keyword{IO}
\keyword{programming}
\concept{Error handling}
\concept{streaming data}