comparison R/rdyncall/demo/expat.R @ 0:0cfcc391201f

initial from svn dyncall-1745
author Daniel Adler
date Thu, 19 Mar 2015 22:26:28 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:0cfcc391201f
1 # Package: rdyncall
2 # File: demo/expat.R
3 # Description: Parsing XML using expat and callbacks
4
5 dynport(expat)
6
7 parser <- XML_ParserCreate(NULL)
8
9 onXMLStartTag <- function(user,tag,attr)
10 {
11 # as.character( as.cstrptrarray(attr) )
12 cat("Start tag:", tag, "\n")
13 }
14
15 onXMLEndTag <- function(user,tag)
16 {
17 cat("End tag:",tag, "\n")
18 }
19
20 cb.onstart <- new.callback("pZp)v", onXMLStartTag )
21 cb.onstop <- new.callback("pZ)v", onXMLEndTag )
22
23 XML_SetElementHandler( parser, cb.onstart, cb.onstop )
24
25 text <- "
26 <hello>
27 <world>
28 </world>
29 </hello>
30 "
31
32 XML_Parse( parser, text, nchar(text), 1)
33