gpt4 book ai didi

xml - 无法为签名 ‘saveXML’ 字符找到函数 ‘"的继承方法”’

转载 作者:数据小太阳 更新时间:2023-10-29 01:40:47 25 4
gpt4 key购买 nike

尝试解析 xml 文件时,我总是遇到此错误。

重现它的简单脚本:

doc <- xmlRoot(xmlTreeParse("http://www.stat.purdue.edu/~mdw/490M/cdcatalog.xml"))

xpathSApply(doc, "//CATALOG/CD/PRICE", xmlValue)

Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘saveXML’ for signature ‘"character"’

加载了以下包:

sessionInfo()
R version 3.1.0 (2014-04-10)
Platform: x86_64-apple-darwin13.1.0 (64-bit)

locale:
[1] de_DE.UTF-8/de_DE.UTF-8/de_DE.UTF-8/C/de_DE.UTF-8/de_DE.UTF-8

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] XML_3.98-1.1

loaded via a namespace (and not attached):
[1] tools_3.1.0

最佳答案

url <- "http://www.stat.purdue.edu/~mdw/490M/cdcatalog.xml"    
doc <- xmlRoot(xmlTreeParse(url, useInternalNodes = TRUE))
xpathSApply(doc, "//CATALOG/CD/PRICE", xmlValue)

我认为这与命名空间的解析有关。 xpath 使用 getNodeSet() 需要 useInternalNodes = TRUE

关于xml - 无法为签名 ‘saveXML’ 字符找到函数 ‘"的继承方法”’,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24118546/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com