尝试在R中解析XML时出错

尝试在R中解析XML时出错,r,xml,data-science,R,Xml,Data Science,我在试图解析R中的xml文件时不断出错 以下是我试图做的: library(XML) fileUrl <- "http://www.w3schools.com/xml/simple.xml" doc <- xmlTreeParse(fileUrl, useInternal=TRUE) " 我在Windows 7上使用的是R版本3.3.2。XML库版本是3.98.1.5。 如果有人能提供帮助,我会很高兴,因为这应该是一个简单的解析,但我被困在这里。对于packageXML来说,它对我

我在试图解析R中的xml文件时不断出错

以下是我试图做的:

library(XML)
fileUrl <- "http://www.w3schools.com/xml/simple.xml"
doc <- xmlTreeParse(fileUrl, useInternal=TRUE)
"

我在Windows 7上使用的是R版本3.3.2。XML库版本是3.98.1.5。


如果有人能提供帮助,我会很高兴,因为这应该是一个简单的解析,但我被困在这里。

对于package
XML
来说,它对我很有用,因为它是输出(使用
dplyr
将输出放在
data.frame
):


您是否尝试过
xmlParse(fileUrl,useInternalNodes=FALSE)
xmlParse()
xmlTreeParse()
都是相同的,只是useInternalNodes的默认值有不同的值。我尝试过这些,但它仍然输出相同的结果。我还是失败了。但我找到了一种方法让它工作。我将simple.xml下载到本地目录,并从本地目录解析xml文件。它工作正常。我不太确定为什么我不能从网站解析。w3schools网站中的xml文件是否可能包含在html中?这就是为什么无法解析它。@ggsdc如果第二种方法成功并获得列表,我将如何将该列表转换为可用的df格式?有什么建议吗?
Opening and ending tag mismatch: meta line 4 and head
StartTag: invalid element name
Opening and ending tag mismatch: br line 73 and p
Opening and ending tag mismatch: br line 94 and body
Opening and ending tag mismatch: br line 93 and html
Premature end of data in tag br line 92
Premature end of data in tag br line 78
Premature end of data in tag br line 77
...
...
16: Premature end of data in tag br line 64
17: Premature end of data in tag body line 63
18: Premature end of data in tag meta line 3
19: Premature end of data in tag head line 2
20: Premature end of data in tag html line 2
library(XML)
library(dplyr)

fileUrl <- "http://www.w3schools.com/xml/simple.xml"
doc <- xmlTreeParse(fileUrl, useInternal=TRUE) %>%
  xmlToDataFrame()
doc

name price                                                                         description calories
1             Belgian Waffles $5.95                   Two of our famous Belgian Waffles with plenty of real maple syrup      650
2  Strawberry Belgian Waffles $7.95                   Light Belgian waffles covered with strawberries and whipped cream      900
3 Berry-Berry Belgian Waffles $8.95 Light Belgian waffles covered with an assortment of fresh berries and whipped cream      900
4                French Toast $4.50                                 Thick slices made from our homemade sourdough bread      600
5         Homestyle Breakfast $6.95                 Two eggs, bacon or sausage, toast, and our ever-popular hash browns      950
library(xml2)
library(dplyr)

fileUrl <- "http://www.w3schools.com/xml/simple.xml"

# As a list
doc <-read_xml(fileUrl) %>% 
  as_list()