只读行读取XML r的头

只读行读取XML r的头,xml,r,rvest,Xml,R,Rvest,我正在下载并解压缩一个包含xml的gz文件。当我使用readLines将xml读入xmlParse时,它只返回标题。但是在文件中有一个完整的结构 可以下载解压缩的xml文件 您不使用XML包功能来解析XML文件有什么原因吗?该文件以gz的形式出现。然后我解压缩它,xmlParse读取readLines输出。所以我使用的是XML包。有没有更好的方法获取数据? library(hvest) url.base="http://prices.shufersal.co.il/FileObject/Upda

我正在下载并解压缩一个包含xml的gz文件。当我使用readLines将xml读入xmlParse时,它只返回标题。但是在文件中有一个完整的结构

可以下载解压缩的xml文件


您不使用XML包功能来解析XML文件有什么原因吗?该文件以gz的形式出现。然后我解压缩它,xmlParse读取readLines输出。所以我使用的是XML包。有没有更好的方法获取数据?
library(hvest)
url.base="http://prices.shufersal.co.il/FileObject/UpdateCategory?catID=0&storeId=0&page="
max.page=as.numeric(gsub("[^1-9]","",html(paste0(url.base,1))%>%html_nodes(xpath="//div[@id='gridContainer']/table/tfoot/tr/td/a[6]")%>%html_attr("href")))
shufersal.url=html(paste0(url.base,max.page))%>%html_nodes("a")%>%html_attr("href")
shufersal.url=shufersal.url[grepl("Store",shufersal.url)]
temp <- tempfile()
download.file(shufersal.url,temp,quiet = T,mode="wb")
readLines(gzfile(temp),encoding = "UTF-8")
  [1] "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
xmlParse(readLines(gzfile(temp),encoding = "UTF-8"))
  Start tag expected, '<' not found
  Error: 1: Start tag expected, '<' not found
unlink(temp)
#I think you can get the contents without using gzfile (not sure why?);
kk<-readLines(temp,encoding = "UTF-8")
jj<-xmlParse(readLines(temp,encoding = "UTF-8"))