November 2016
Beginner to intermediate
959 pages
43h 46m
English
You may sometimes need to extract data from websites. Many providers also supply data in XML and JSON formats. In this recipe, we learn about reading XML data.
If the XML package is not already installed in your R environment, install the package now as follows:
> install.packages("XML")XML data can be read by following these steps:
> library(XML) > url <- "http://www.w3schools.com/xml/cd_catalog.xml"
> xmldoc <- xmlParse(url) > rootNode <- xmlRoot(xmldoc) > rootNode[1]
> data <- xmlSApply(rootNode,function(x) xmlSApply(x, xmlValue))
> cd.catalog <- data.frame(t(data),row.names=NULL) ...
Read now
Unlock full access