Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unable to find an inherited method for function ‘saveXML’ for signature ‘"character"’

Tags:

r

xml

When trying to parse a xml file I get always this error.

A simple script to reproduce it:

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"’

The following packages are loaded:

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
like image 960
JerryWho Avatar asked Jun 09 '14 10:06

JerryWho


1 Answers

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

I think this has got to do with resolution of namespaces. useInternalNodes = TRUE is required for xpath to use getNodeSet()

like image 182
lazycoder Avatar answered Sep 28 '22 23:09

lazycoder