简体   繁体   English

R编程xmlTreeParse XML内容似乎不是XML

[英]R programming xmlTreeParse XML content does not seem to be XML

I use R to parse the xml https://d396qusza40orc.cloudfront.net/getdata%2Fdata%2Frestaurants.xml . 我使用R解析xml https://d396qusza40orc.cloudfront.net/getdata%2Fdata%2Frestaurants.xml This xml exists, but R remind me that it does not seem to be XML. 该xml存在,但是R提醒我它似乎不是XML。

Try using http instead of https : 尝试使用http而不是https:

library(XML)
u <- "http://d396qusza40orc.cloudfront.net/getdata%2Fdata%2Frestaurants.xml"
doc <- xmlTreeParse(u, useInternalNodes = TRUE)

I had the same problem. 我有同样的问题。 I learnt that xmlTreeParse does not work with https. 我了解到xmlTreeParse不适用于https。 While the solution recommended by Grothendieck would work, sometimes you have to use https for added security, so if that is your situation then it is better to load the library RCurl and get the document using getURL. 尽管Grothendieck推荐的解决方案可行,但有时您必须使用https以增强安全性,因此,如果您遇到这种情况,则最好加载RCurl库并使用getURL获取文档。 You can then parse it in XML. 然后,您可以将其解析为XML。 It worked for me as follows: 它为我工作如下:

library(RCurl)
library(XML)
temp <- getURL("https://d396qusza40orc.cloudfront.net/getdata%2Fdata%2Frestaurants.xml")
doc <- xmlTreeParse(temp, useInternalNodes = TRUE)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM