【发布时间】:2016-07-08 20:29:12
【问题描述】:
我对此完全不了解。我正在尝试使用闭包函数读取一个大型 xml 文件。唯一的问题是,我无法找到一种在关闭中创建柜台的方法,以便我可以将柜台用作商店位置的 id。我想出了以下代码,它显然存在一些(或可能是严重的)问题。
branchFunction <- function() {
store <- new.env()
func <- function(x, ...) {
new_counter <- function() {
i <- 0
function() {
i <<- i + 1
i
}
}
ns <- getNodeSet(x,path = "//event[@type='left link' or @type='entered link']")
value <- lapply(ns, xmlAttrs)
store[[i]] <- value
}
getStore <- function() { as.list( store ) }
list(event = func, getStore=getStore)
}
myfunctions <- branchFunction()
xmlEventParse(file = "xml.xml", handlers = NULL, branches = myfunctions)
#to see what is inside
l <- myfunctions$getStore()
这里是示例data。
【问题讨论】:
标签: r xml-parsing closures sax