xmlTreeParse Fails with error “XML content does not seem to be XML”

Code below is run in RSTUDIO.

  • fileURL is the variable that holds the internet location of the XML file in question
  • doc is the variable to store the output of xmlTreeParse

> fileUrl doc <- xmlTreeParse(fileUrl,useInternal=TRUE)
Error: XML content does not seem to be XML: ‘https://www.w3schools.com/xml/simple.xml&#8217;

SOLUTION: Install package RCurl and use function getURL on the link to the XML file  first

WARNING: Rtools is required to build R packages but is not currently installed. Please download and install the appropriate version of Rtools before proceeding:

also installing the dependency ‘bitops’

trying URL ‘https://cran.rstudio.com/bin/windows/contrib/3.5/bitops_1.0-6.zip&#8217;
Content type ‘application/zip’ length 38894 bytes (37 KB)
downloaded 37 KB

trying URL ‘https://cran.rstudio.com/bin/windows/contrib/3.5/RCurl_1.95-4.12.zip&#8217;
Content type ‘application/zip’ length 2968691 bytes (2.8 MB)
downloaded 2.8 MB
> library(RCurl)
Loading required package: bitops
> xData <- getURL (fileUrl)
> doc <- xmlTreeParse(xData)
> doc