简体   繁体   English

无法读取 R 中的 XML 文件以转换 dataframe?

[英]Cannot read XML file in R to convert a dataframe?

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)尝试从 FAERS 读取library(XML)文件并将其转换为DataFrame但无法读取R 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 linkOct-Dec,2012数据可在2012 年 10 月至 12 月的链接中免费获得

I have tried these -- Reading xml and utf8_encode(.) does not work in R我已经尝试过这些—— 读取 xmlutf8_encode(.)在 R 中不起作用

Try this:尝试这个:

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

You have documentation here .你有文档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 )我正在处理您在问题中指定的文件( 3_ADR20Q1.xml

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM