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

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

https://cran.rstudio.com/bin/windows/Rtools/
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
$doc
$file
[1]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.