0

Trying to read and convert a XML file to DataFrame from FAERS but cannot read the file in R So far I have tried both library(XML) and library(xml2)

This error appears I have tried solutions online but does not work

> library(xml2)
> pg <- read_xml("faers/xml/ADR12Q4.xml")
Error in read_xml.character("faers/xml/ADR12Q4.xml") : 
  Input is not proper UTF-8, indicate encoding !
Bytes: 0xB5 0x67 0x2F 0x64 [9]

Data is freely available in the link Oct-Dec,2012

I have tried these -- Reading xml and utf8_encode(.) does not work in R

iHermes
  • 314
  • 3
  • 12
  • Please include sample of XML in body of question (including its root and enough elements to understand structure) to avoid readers the burden of downloading form external links that may not be available or accessible by all now or in future. – Parfait Jul 16 '20 at 18:02

1 Answers1

1

Try this:

> pg <- read_xml('path', encoding='UTF-8')

You have documentation here.

Edit: Try this code:

result <- XML::xmlParse("path_to_file")

This code worked for me. I was working of file that you specified in your question (3_ADR20Q1.xml)

777moneymaker
  • 697
  • 4
  • 15
  • still getting same error, " Input is not proper UTF-8, indicate encoding ! Bytes: 0xB5 0x67 0x2F 0x64 [9]" – iHermes Jul 16 '20 at 16:05
  • So you have an answer. You have to check, what encoding you have in that file, and then pass is as an argument. You can check it in the first line of XML file. – 777moneymaker Jul 16 '20 at 16:09