https://github.com/cran/XML
Raw File
Tip revision: 6ac5aacfa6b8250c6501b2fe1c24fc9f287f02f3 authored by Duncan Temple Lang on 29 April 2011, 00:00:00 UTC
version 3.4-0
Tip revision: 6ac5aac
genericHandlers.R
# This illustrates using the new naming scheme for generic handlers
# that use a . prefix.

h =
  list(.text = function(content) cat("text:", xmlValue(content), "\n"),
       .comment = function(node) cat("##", xmlValue(node), "\n"),
       .processingInstruction = function(target, content) cat("PI: [", target, "]", content, "\n"),
       .startElement = function(node, attrs) { cat("New node:", xmlName(node), paste(names(xmlAttrs(node)), collapse = ", "), "\n")},
       .endElement = function(node) { cat("end node:", node, "\n")},
       .startDocument = function(...) cat("start of document\n"),
       .endDocument = function(...) cat("end of document\n"),
       .cdata = function(node) cat("CDATA:", xmlValue(node), "\n")
      )

xmlTreeParse("test.xml", handlers = h, asTree = TRUE, useDotNames = TRUE)
back to top