Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

xmlParserContextFunction

Identifies function as expecting an xmlParserContext argument


Description

This is a convenience function for setting the class of the specified function to include "XMLParserContextFunction". This identifies it as expecting an xmlParserCtxt object as its first argument. The resulting function can be passed to the internal/native XML parser as a handler/callback function. When the parser calls it, it recognizes this class information and includes a reference to the C-level xmlParserCtxt object as the first argument in the call.

This xmlParserCtxt object can be used to gracefully terminate the parsing (without an error), and in the future will also provide access to details about the current state of the parser, e.g. the encoding of the file, the XML version, whether entities are being replaced, line and column number for each node processed.

Usage

xmlParserContextFunction(f, class = "XMLParserContextFunction")

Arguments

f

the function whose class information is to be augmented.

class

the name of the class which is to be added to the class attribute of the function.

Value

The function object f whose class attribute has been prepended with the value of class.

Author(s)

Duncan Temple Lang

See Also

xmlInternalTreeParse/xmlParse and the branches parameter of xmlEventParse.

Examples

fun = function(context, ...) {
             # do things to parse the node
             # using the context if necessary.
           cat("In XMLParserContextFunction\n")
           xmlStopParser(context)
         }
  fun = xmlParserContextFunction(fun)

  txt = "<doc><a/></doc>"
  # doesn't work for xmlTreeParse()
  #   xmlTreeParse(txt, handlers = list(a = fun))

  #  but does in xmlEventParse().
  xmlEventParse(txt, handlers = list(startElement = fun), asText = TRUE)

XML

Tools for Parsing and Generating XML Within R and S-Plus

v3.99-0.10
BSD_3_clause + file LICENSE
Authors
CRAN Team [ctb, cre] (de facto maintainer since 2013), Duncan Temple Lang [aut] (<https://orcid.org/0000-0003-0159-1546>), Tomas Kalibera [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.