File: itunesSax2.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 (31 lines) | stat: -rw-r--r-- 630 bytes parent folder | download | duplicates (9)
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
# This version works on the generic plist form
# We want the dict/dict/dict

depth = 0
count = 0
songs = vector("list", 1300)

songNode =
function(parser, node)
{
  count <<- count + 1
  songs[[count]] <<- node
}
class(songNode) = c("XMLParserContextFunction", "SAXBranchFunction")

dict =
function(parser, node, ...)
{
  print(depth)
  if(depth == 2) {
      # return the songNode function so that it will be used as a branch
      # function for this <dict> node, i.e. will be invoked
    return(songNode)
  } else
    depth <<- depth + 1


  TRUE
}

xmlEventParse("~/itunes.xml", handlers = list(dict = dict), saxVersion = 2L)