Set XML_PARSE_HUGE option for xml2::xml_text() in

2019-03-01 18:47发布

问题:

I've read this question Parse XML Files (>1 megabyte) in R and this answer seems to only apply to the original XML package in R. How do I set this option in xml2?

Here is the code I'm running:

library(xml2)
library(magrittr)

rawXML <- read_xml(xmlFile)
emails <- xml_find_all(rawXML, "//header")

emailElements <- sapply(1:length(emails), function(idx) {
attrs <- xml_attrs(emails[idx])[[1]]
index <- attrs['index']
sender <- attrs['from']
...
contentLink <- attrs['contentLink'] #is a *.html file
rawContentText <- read_html(contentLink)
content <- xml_text(rawContentText)
...
v <- c(index, date, sender, subject, headerLink, rawLink, contentLink, content, attachmentLink)
return(v)
})

Here is the error I get:

Error: Excessive depth in document: 256 use XML_PARSE_HUGE option [1]

Thanks in advance.