Error: XML content does not seem to be XML

I am trying to execute the following lines of code:

url <--""
doc <- xmlTreeParse(url, useInternal=TRUE)

But I am getting this error message.

Okay so I’m not going deep into the technicality of the ERROR just to make you understand whats going on.

The error you’re getting is because You’re directly parsing the url which is not even xml
url <--""

You’re Parsing “” (Imagine how can this string be treated as xml)

You need to make a get request which saves the response in a string with a read object to it, You can then easily parse it with the xml parser. Try this code.

url <--""
r = GET(url)
doc <- xmlTreeParse(r, useInternal=TRUE)

You will get what you’re looking for even if you don’t specify the encoding.

1 Like