Running examples in ‘XML-Ex.R’ failed
The error most likely occurred in:

> ### Name: xmlEventParse
> ### Title: XML Event/Callback element-wise Parser
> ### Aliases: xmlEventParse
> ### Keywords: file IO
> 
> ### ** Examples
> 
>  fileName <- system.file("exampleData", "mtcars.xml", package="XML")
> 
>    # Print the name of each XML tag encountered at the beginning of each
>    # tag.
>    # Uses the libxml SAX parser.
>  xmlEventParse(fileName,
+                 list(startElement=function(name, attrs){
+                                     cat(name,"\n")
+                                   }),
+                 useTagName=FALSE, addContext = FALSE)
dataset 
variables 
variable 
variable 
variable 
variable 
variable 
variable 
variable 
variable 
variable 
variable 
variable 
record 
record 
record 
record 
record 
record 
record 
record 
record 
record 
record 
record 
record 
record 
record 
record 
record 
record 
record 
record 
record 
record 
record 
record 
record 
record 
record 
record 
record 
record 
record 
record 
$startElement
function (name, attrs) 
{
    cat(name, "\n")
}
<bytecode: 0x8adfa40>

> 
> 
> ## Not run: 
> ##D   # Parse the text rather than a file or URL by reading the URL's contents
> ##D   # and making it a single string. Then call xmlEventParse
> ##D xmlURL <- "http://www.omegahat.net/Scripts/Data/mtcars.xml"
> ##D xmlText <- paste(scan(xmlURL, what="",sep="\n"),"\n",collapse="\n")
> ##D xmlEventParse(xmlText, asText=TRUE)
> ## End(Not run)
> 
>     # Using a state object to share mutable data across callbacks
> f <- system.file("exampleData", "gnumeric.xml", package = "XML")
> zz <- xmlEventParse(f,
+                     handlers = list(startElement=function(name, atts, .state) {
+                                                      .state = .state + 1
+                                                      print(.state)
+                                                      .state
+                                                  }), state = 0)
[1] 1
[1] 2
[1] 3
[1] 4
[1] 5
[1] 6
[1] 7
[1] 8
[1] 9
[1] 10
[1] 11
[1] 12
[1] 13
[1] 14
[1] 15
[1] 16
[1] 17
[1] 18
[1] 19
[1] 20
[1] 21
[1] 22
[1] 23
[1] 24
[1] 25
[1] 26
[1] 27
[1] 28
[1] 29
[1] 30
[1] 31
[1] 32
[1] 33
[1] 34
[1] 35
[1] 36
[1] 37
[1] 38
[1] 39
[1] 40
[1] 41
[1] 42
[1] 43
[1] 44
[1] 45
[1] 46
[1] 47
[1] 48
[1] 49
[1] 50
[1] 51
[1] 52
[1] 53
[1] 54
[1] 55
[1] 56
[1] 57
[1] 58
> print(zz)
[1] 58
> 
> 
> 
> 
>     # Illustrate the startDocument and endDocument handlers.
> xmlEventParse(fileName,
+                handlers = list(startDocument = function() {
+                                                  cat("Starting document\n")
+                                                },
+                                endDocument = function() {
+                                                  cat("ending document\n")
+                                              }),
+                saxVersion = 2)
Starting document
ending document
$startDocument
function () 
{
    cat("Starting document\n")
}

$endDocument
function () 
{
    cat("ending document\n")
}

> 
> 
> 
> 
> if(libxmlVersion()$major >= 2) {
+ 
+ 
+  startElement = function(x, ...) cat(x, "\n")
+ 
+  xmlEventParse(file(f), handlers = list(startElement = startElement))
+ 
+ 
+  # Parse with a function providing the input as needed.
+  xmlConnection = 
+   function(con) {
+ 
+    if(is.character(con))
+      con = file(con, "r")
+   
+    if(isOpen(con, "r"))
+      open(con, "r")
+ 
+    function(len) {
+ 
+      if(len < 0) {
+         close(con)
+         return(character(0))
+      }
+ 
+       x = character(0)
+       tmp = ""
+     while(length(tmp) > 0 && nchar(tmp) == 0) {
+       tmp = readLines(con, 1)
+       if(length(tmp) == 0)
+         break
+       if(nchar(tmp) == 0)
+         x = append(x, "\n")
+       else
+         x = tmp
+     }
+     if(length(tmp) == 0)
+       return(tmp)
+   
+     x = paste(x, collapse="")
+ 
+     x
+   }
+  }
+ 
+  ff = xmlConnection(f)
+  xmlEventParse(ff, handlers = list(startElement = startElement))
+ 
+   # Parse from a connection. Each time the parser needs more input, it
+   # calls readLines(<con>, 1)
+  xmlEventParse(file(f),  handlers = list(startElement = startElement))
+ 
+ 
+   # using SAX 2
+  h = list(startElement = function(name, attrs, namespace, allNamespaces){ 
+                                  cat("Starting", name,"\n")
+                                  if(length(attrs))
+                                      print(attrs)
+                                  print(namespace)
+                                  print(allNamespaces)
+                          },
+           endElement = function(name, uri) {
+                           cat("Finishing", name, "\n")
+             }) 
+  xmlEventParse(system.file("exampleData", "namespaces.xml", package="XML"),
+                handlers = h, saxVersion = 2)
+ 
+ 
+  # This example is not very realistic but illustrates how to use the
+  # branches argument. It forces the creation of complete nodes for
+  # elements named <b> and extracts the id attribute.
+  # This could be done directly on the startElement, but this just
+  # illustrates the mechanism.
+  filename = system.file("exampleData", "branch.xml", package="XML")
+  b.counter = function() {
+                 nodes <- character()
+                 f = function(node) { nodes <<- c(nodes, xmlGetAttr(node, "id"))}
+                 list(b = f, nodes = function() nodes)
+              }
+ 
+   b = b.counter()
+   invisible(xmlEventParse(filename, branches = b["b"]))
+   b$nodes()
+ 
+ 
+   filename = system.file("exampleData", "branch.xml", package="XML")
+    
+   invisible(xmlEventParse(filename, branches = list(b = function(node) {
+                           print(names(node))})))
+   invisible(xmlEventParse(filename, branches = list(b = function(node) {
+                           print(xmlName(xmlChildren(node)[[1]]))})))
+ }
gmr:Workbook 
gmr:Summary 
gmr:Item 
gmr:name 
gmr:val-string 
gmr:Item 
gmr:name 
gmr:val-string 
gmr:Geometry 
gmr:Sheets 
gmr:Sheet 
gmr:Name 
gmr:MaxCol 
gmr:MaxRow 
gmr:Zoom 
gmr:CellStyles 
gmr:Style 
gmr:Font 
gmr:Style 
gmr:Font 
gmr:Style 
gmr:Font 
gmr:Cols 
gmr:ColInfo 
gmr:ColInfo 
gmr:Rows 
gmr:RowInfo 
gmr:RowInfo 
gmr:RowInfo 
gmr:RowInfo 
gmr:RowInfo 
gmr:RowInfo 
gmr:RowInfo 
gmr:Cells 
gmr:Cell 
gmr:Content 
gmr:Cell 
gmr:Content 
gmr:Cell 
gmr:Content 
gmr:Cell 
gmr:Content 
gmr:Cell 
gmr:Content 
gmr:Cell 
gmr:Content 
gmr:Cell 
gmr:Content 
gmr:Cell 
gmr:Content 
gmr:Cell 
gmr:Content 
gmr:Cell 
gmr:Content 
gmr:Cell 
gmr:Content 
gmr:Cell 
gmr:Content 
Warning in open.connection(con, "r") : connection is already open
gmr:Workbook 
gmr:Summary 
gmr:Item 
gmr:name 
gmr:val-string 
gmr:Item 
gmr:name 
gmr:val-string 
gmr:Geometry 
gmr:Sheets 
gmr:Sheet 
gmr:Name 
gmr:MaxCol 
gmr:MaxRow 
gmr:Zoom 
gmr:CellStyles 
gmr:Style 
gmr:Font 
gmr:Style 
gmr:Font 
gmr:Style 
gmr:Font 
gmr:Cols 
gmr:ColInfo 
gmr:ColInfo 
gmr:Rows 
gmr:RowInfo 
gmr:RowInfo 
gmr:RowInfo 
gmr:RowInfo 
gmr:RowInfo 
gmr:RowInfo 
gmr:RowInfo 
gmr:Cells 
gmr:Cell 
gmr:Content 
gmr:Cell 
gmr:Content 
gmr:Cell 
gmr:Content 
gmr:Cell 
gmr:Content 
gmr:Cell 
gmr:Content 
gmr:Cell 
gmr:Content 
gmr:Cell 
gmr:Content 
gmr:Cell 
gmr:Content 
gmr:Cell 
gmr:Content 
gmr:Cell 
gmr:Content 
gmr:Cell 
gmr:Content 
gmr:Cell 
gmr:Content 
gmr:Workbook 
gmr:Summary 
gmr:Item 
gmr:name 
gmr:val-string 
gmr:Item 
gmr:name 
gmr:val-string 
gmr:Geometry 
gmr:Sheets 
gmr:Sheet 
gmr:Name 
gmr:MaxCol 
gmr:MaxRow 
gmr:Zoom 
gmr:CellStyles 
gmr:Style 
gmr:Font 
gmr:Style 
gmr:Font 
gmr:Style 
gmr:Font 
gmr:Cols 
gmr:ColInfo 
gmr:ColInfo 
gmr:Rows 
gmr:RowInfo 
gmr:RowInfo 
gmr:RowInfo 
gmr:RowInfo 
gmr:RowInfo 
gmr:RowInfo 
gmr:RowInfo 
gmr:Cells 
gmr:Cell 
gmr:Content 
gmr:Cell 
gmr:Content 
gmr:Cell 
gmr:Content 
gmr:Cell 
gmr:Content 
gmr:Cell 
gmr:Content 
gmr:Cell 
gmr:Content 
gmr:Cell 
gmr:Content 
gmr:Cell 
gmr:Content 
gmr:Cell 
gmr:Content 
gmr:Cell 
gmr:Content 
gmr:Cell 
gmr:Content 
gmr:Cell 
gmr:Content 
Starting a 
                          
"http://www.omegahat.net" 
                                             omegahat 
 "http://www.omegahat.net"  "http://www.omegahat.net" 
                         r 
"http://www.r-project.org" 
Starting b 
      foo 
"myValue" 
attr(,"namespaces")
                 omegahat 
"http://www.omegahat.net" 
                         r 
"http://www.r-project.org" 
named character(0)
Starting defaultNs 
                          
"http://www.omegahat.net" 
named character(0)
Finishing defaultNs 
Starting c 
                 c 
"http://www.c.org" 
                 c 
"http://www.c.org" 
Finishing c 
Finishing b 
Finishing a 
  text      f      g 
"text"    "f"    "g" 
      f   g 
 NA "f" "g" 
  f   g 
"f" "g" 
  f   g   b 
"f" "g" "b" 
[1] "text"
[1] NA
[1] "f"
[1] "f"
> 
>   
>   ############################################
>   # 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: 0xb797c50>
attr(,"class")
[1] "XMLParserContext"
[1] "catalog"
<pointer: 0xb797c50>
attr(,"class")
[1] "XMLParserContext"
[1] "group"
<pointer: 0xb797c50>
attr(,"class")
[1] "XMLParserContext"
[1] "public"
ending public 
<pointer: 0xb797c50>
attr(,"class")
[1] "XMLParserContext"
[1] "system"
ending system 
<pointer: 0xb797c50>
attr(,"class")
[1] "XMLParserContext"
[1] "system"
ending system 
ending group 
<pointer: 0xb797c50>
attr(,"class")
[1] "XMLParserContext"
[1] "uri"
ending uri 
<pointer: 0xb797c50>
attr(,"class")
[1] "XMLParserContext"
[1] "rewriteURI"
Terminating parser
$startElement
function (ctxt, name, attrs, ...) 
{
    print(ctxt)
    print(name)
    if (name == "rewriteURI") {
        cat("Terminating parser\n")
        xmlStopParser(ctxt)
    }
}
<bytecode: 0x40ea8b8>
attr(,"class")
[1] "XMLParserContextFunction"

$endElement
function (name, ...) 
cat("ending", name, "\n")
<bytecode: 0x3faf230>

> 
> 
> 
> cleanEx()
Error: connections left open:
	/data/gannet/ripley/R/packages/tests-devel/XML.Rcheck/XML/exampleData/gnumeric.xml (file)
	/data/gannet/ripley/R/packages/tests-devel/XML.Rcheck/XML/exampleData/gnumeric.xml (file)
	/data/gannet/ripley/R/packages/tests-devel/XML.Rcheck/XML/exampleData/gnumeric.xml (file)
Execution halted