【发布时间】:2014-08-01 12:54:49
【问题描述】:
我在将 xml 文件读入 R 时遇到问题。问题是,这个 xml 文件没有 .xml 扩展名。
我通常会遵循以下描述的方法:
library(XML)
xml.url <- "http://www.w3schools.com/xml/plant_catalog.xml"
使用xmlTreeParse和readLines函数解析xml文件:
xmlfile <- xmlTreeParse(readLines(xml.url))
但是,我不知道如何解析下面网页中的内容。它没有 .xml 扩展名。
my_file <-
paste0("http://ec.europa.eu/public_opinion/cf/",
"exp_feed.cfm?keyID=1&nationID=",
"11,1,27,28,17,2,16,18,13,32,6,3,4,",
"22,33,7,8,20,21,9,23,31,34,24,12,19,",
"35,29,26,25,5,14,10,30,15,",
"&startdate=1973.09&enddate=",
"2014.06")
my_xml_file <- xmlTreeParse(readLines(my_file))
我收到此错误:
Input is not proper UTF-8, indicate encoding !
Bytes: 0xE7 0x6F 0x6E 0x20
Error: 1: Input is not proper UTF-8, indicate encoding !
Bytes: 0xE7 0x6F 0x6E 0x20
所以,网页没有扩展名,解析会抛出与编码有关的错误。我在上面的函数中尝试了编码参数的运气......没有运气。
【问题讨论】: