
上QQ阅读APP看书,第一时间看更新
How to do it...
XML data can be read by following these steps:
- Load the library and initialize:
> library(XML)
> url <- "cd_catalog.xml"
- Parse the XML file and get the root node:
> xmldoc <- xmlParse(url)
> rootNode <- xmlRoot(xmldoc)
> rootNode[1]
- Extract the XML data:
> data <- xmlSApply(rootNode,function(x) xmlSApply(x, xmlValue))
- Convert the extracted data into a data frame:
> cd.catalog <- data.frame(t(data),row.names=NULL)
- Verify the results:
> cd.catalog[1:2,]