'externalptr' error in R using XML data

2020-05-26 09:23发布

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

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

Any suggestions? Thanks - Z

标签: xml r
3条回答
可以哭但决不认输i
2楼-- · 2020-05-26 10:02

I know this is an old thread, but to understand in detail about external pointer I feel it is important to understand when it is used. This thread tells the difference between xmlParse and xmlTreeParse, when to use it, and how it works (pointer vs object).

查看更多
够拽才男人
3楼-- · 2020-05-26 10:10

I managed to write the content of an XML tree to a file using the saveXML() command from the XML package:

saveXML(xml[[1]], file="output.xml")

Hope this helps.

查看更多
乱世女痞
4楼-- · 2020-05-26 10:23

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

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

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

查看更多
登录 后发表回答