使用XML数据的R中的'externalptr'错误

use*_*253 14 xml r

我正在使用R中的一些XML数据并遇到类型'externalptr'的错误.

1)当我尝试使用xmlInternalTreeParse()函数(XML包的一部分)时,我收到以下错误.

 doc = xmlInternalTreeParse(xmldatavariable)
    'Error in as.vector(x, "character") : cannot coerce type 'externalptr'
 to vector of type 'character''
Run Code Online (Sandbox Code Playgroud)

2)当我尝试将XML数据写入文本文件时,我收到此错误,因此我可以查看它并查看错误可能是什么.

write(xmldatavariable,"sample.txt")
Error in cat(list(...), file, sep, fill, labels, append) : 
      argument 1 (type 'externalptr') cannot be handled by 'cat'
Run Code Online (Sandbox Code Playgroud)

有什么建议?谢谢 - Z.

Mis*_*urg 6

XML包通过制作您试图操作的XML文档的指针文档来工作.

'externalptr'只是xml文档中数据的外部指针.

要访问您需要使用的数据

Parsed.xml <- xmlTreeParse(xml) ## should be string with xml text
## get value of the first node
xmlValue(xml[[1]])
## get value of the third grandchild of the first node
xmlValue(xml[[1]][[45]][[3]])   
Run Code Online (Sandbox Code Playgroud)

您需要以列表的形式访问xml的每个节点.