Examples for 'XML::xmlStopParser'


Terminate an XML parser

Aliases: xmlStopParser

Keywords: IO programming

### ** 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))
<pointer: 0x55ccfeefde60>
attr(,"class")
[1] "XMLParserContext"
[1] "catalog"
<pointer: 0x55ccfeefde60>
attr(,"class")
[1] "XMLParserContext"
[1] "group"
<pointer: 0x55ccfeefde60>
attr(,"class")
[1] "XMLParserContext"
[1] "public"
ending public 
<pointer: 0x55ccfeefde60>
attr(,"class")
[1] "XMLParserContext"
[1] "system"
ending system 
<pointer: 0x55ccfeefde60>
attr(,"class")
[1] "XMLParserContext"
[1] "system"
ending system 
ending group 
<pointer: 0x55ccfeefde60>
attr(,"class")
[1] "XMLParserContext"
[1] "uri"
ending uri 
<pointer: 0x55ccfeefde60>
attr(,"class")
[1] "XMLParserContext"
[1] "rewriteURI"
Terminating parser
$startElement
<srcref: file "" chars 10:3 to 17:3>
<environment: 0x55ccfc636e38>
attr(,"class")
[1] "XMLParserContextFunction"

$endElement
<srcref: file "" chars 20:3 to 21:29>
<environment: 0x55ccfc636e38>

[Package XML version 3.99-0.10 Index]