annotate R/rdyncall/demo/expat.R @ 52:c5ca08cd3e78

- readme typos
author Tassilo Philipp
date Fri, 22 Jan 2021 15:12:34 +0100
parents 0cfcc391201f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
1 # Package: rdyncall
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
2 # File: demo/expat.R
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
3 # Description: Parsing XML using expat and callbacks
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
4
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
5 dynport(expat)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
6
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
7 parser <- XML_ParserCreate(NULL)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
8
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
9 onXMLStartTag <- function(user,tag,attr)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
10 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
11 # as.character( as.cstrptrarray(attr) )
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
12 cat("Start tag:", tag, "\n")
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
13 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
14
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
15 onXMLEndTag <- function(user,tag)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
16 {
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
17 cat("End tag:",tag, "\n")
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
18 }
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
19
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
20 cb.onstart <- new.callback("pZp)v", onXMLStartTag )
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
21 cb.onstop <- new.callback("pZ)v", onXMLEndTag )
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
22
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
23 XML_SetElementHandler( parser, cb.onstart, cb.onstop )
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
24
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
25 text <- "
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
26 <hello>
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
27 <world>
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
28 </world>
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
29 </hello>
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
30 "
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
31
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
32 XML_Parse( parser, text, nchar(text), 1)
0cfcc391201f initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
33