Learn R Programming

XML2R (version 0.0.9)

XML2R: Parse XML files into (a list of) matrices or data frame(s)

Description

This function is a wrapper around XML2Obs. One should only use this function over XML2Obs if keys already exist in the XML data and ancestory doesn't need to be altered.

Usage

XML2R(urls, xpath, df = FALSE)

Value

Returns list with one element for each relevant XML node. Each element contains a matrix by default.

Arguments

urls

character vector or list of urls that point to an XML file (or anything readable by [XML::xmlParse()]).

xpath

XML XPath expression that is passed to [XML::getNodeSet()]. If missing, the entire root and all descendents are captured and returned (ie, tables = "/").

df

logical. Should matrices be coerced into data frames?

See Also

urlsToDocs, docsToNodes, nodesToList, listsToObs

Examples

Run this code
if (FALSE) {
urls2 <- c("http://gd2.mlb.com/components/game/mlb/year_2013/mobile/346180.xml",
           "http://gd2.mlb.com/components/game/mlb/year_2013/mobile/346188.xml")
dat3 <- XML2R(urls2)

cens <- "http://www.census.gov/developers/data/sf1.xml"
census <- XML2R(cens)
}

Run the code above in your browser using DataLab