Description Usage Arguments Value Examples
xml2JSON
Convert a well-formed (but not necessarily valid) XML string into a JSON string. Some information may be lost in this transformation because JSON is a data format and XML is a document format. XML uses elements, attributes, and content text, while JSON uses unordered collections of name/value pairs and arrays of values. JSON does not does not like to distinguish between elements and attributes. Sequences of similar elements are represented as JSONArrays. Content text may be placed in a "content" member. Comments, prologs, DTDs, and <[ [ ]]> are ignored.
1 | xml2JSON(xmlString)
|
xmlString |
A character string of XML text |
A JSON string to be parsed containing the structured data from the XML string.
1 2 3 4 5 6 7 8 9 10 | ## Not run:
library(XML)
library(RJSONIO)
fileURL <- "http://api.sportsdatallc.org/nfl-t1/2013/REG/1/statistics.xml?api_key=4dhyq3f3rfkp2cbm4yqbcuag"
xData <- readLines(fileURL)
jData <- xml2JSON(paste(xData, collapse='')) # convert to JSON
out <- fromJSON(jData)
do.call(rbind.data.frame, out$games$game[[1]]$team[[1]][[c('defense', 'player')]])
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.