xml2JSON: Convert a XML string to JSON

Description Usage Arguments Value Examples

Description

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.

Usage

1
xml2JSON(xmlString)

Arguments

xmlString

A character string of XML text

Value

A JSON string to be parsed containing the structured data from the XML string.

Examples

 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)

johndharrison/JSON2XML documentation built on May 19, 2019, 4:22 p.m.