File: connections1.R

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 (39 lines) | stat: -rw-r--r-- 824 bytes parent folder | download | duplicates (11)
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
# Tests reading from a connection.
# Trying to get the newlines.

library(XML)
ReadLines =
  function(con, n) {
    x = readLines(con, 1)

#This works, but tagging the new line doesn't.    
  return(x)

    if(length(x))
      x = paste(x, "<!-- comment -->", sep="")
print(x)
    x
}

handlers =
function() {
  tags = character(0)
  atts = character(0)
  text = character(0)
  startElement = function(x, attrs) {
   tags <<- append(tags, x)
   atts <<- append(atts, attrs)
  }
  addText = function(txt, ...) {
   text <<- append(text, txt) 
  }

  list(startElement = startElement, text = addText, .value = function() { list(tags, atts, text)},
       cdata = function(x) addText(x))
}

h = handlers()
invisible(xmlEventParse(file(system.file("exampleData", "cdata.xml", package = "XML"), "r"), handlers = h))

h$.value()