Parsing small web page with xml2 throws XML_PARSE_

2019-05-30 18:07发布

问题:

Recently a user of my rNOMADS package in R began getting unexpected errors:

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

We tracked the issue down to this command:

html.tmp <- xml2::read_html("http://nomads.ncep.noaa.gov/cgi-bin/filter_rap.pl?dir=%2Frap.20151120")

Upon following the link, it appears that the web page to be parsed is no larger than other ones that work fine, and much less than the 1 megabyte limit that should require the XML_PARSE_HUGE option. Furthermore,

xml2::read_html

actually has no XML_PARSE_HUGE option anyway. The only other potential solution, described here, is not appropriate for an official R package.

What is the cause of this error, and is it possible to resolve it without resorting to solutions outside the official CRAN repository?

回答1:

The best I can do so far is to install shabbychef's forked version of xml2 that forces XML_PARSE_HUGE. You can install this version of xml2 via

library(drat)
drat:::add("shabbychef")
install.packages('xml2')

For the time being, please use this work around if you encounter XML_PARSE_HUGE errors in rNOMADS.