使用 XML 数据的 R 中的“externalptr"错误 [英] 'externalptr' error in R using XML data

查看:22
本文介绍了使用 XML 数据的 R 中的“externalptr"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 R 中处理一些 XML 数据,但遇到了有关externalptr"类型的错误.

I am working with some XML data in R and running into errors regarding type 'externalptr'.

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

1) I get the following error when I try to use the xmlInternalTreeParse() function (part of XML package).

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

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

2) I get this error when I try to write the XML data to a text file so I can look at it and see what the error might be.

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

有什么建议吗?谢谢 - Z

Any suggestions? Thanks - Z

推荐答案

XML 包的工作原理是让您尝试操作的 XML 文档的指针文档.

The XML package works by making pointer document of the XML document your trying to manipulate.

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

The 'externalptr' are simply external pointers to the data within the xml document.

要访问您需要使用的数据

To access the data you need to use

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]])   

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

You need to access each node of the xml as a list.

这篇关于使用 XML 数据的 R 中的“externalptr"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆