readLines only reading header of XML r

I am downloading and unzipping a gz file that contains an xml. When I use readLines to read the xml into xmlParse, it only returns the header. But in the file there is a full structure

unzipped xml file can be downloaded here

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)


Source: xml

Leave a Reply