| xml2json | R Documentation |
Convert XML to a JSON string.
xml2json( xml, spaces = 2L, linebreaks = FALSE, replacer = NULL, attributeNamePrefix = "@_", textNodeName = "#text", ignoreAttributes = FALSE, ignoreNameSpace = FALSE, parseNodeValue = TRUE, parseAttributeValue = TRUE, trimValues = TRUE )
xml |
either a XML file or some XML given as a character string |
spaces |
an integer, the indentation |
linebreaks |
Boolean, whether to break the lines in the JSON string when there are some linebreaks; this generates an invalid JSON string |
replacer |
character vector, the body of the second argument of
|
attributeNamePrefix |
prefix for the attributes |
textNodeName |
name of text nodes, which appear for nodes which have both a text content and some attributes |
ignoreAttributes |
Boolean, whether to ignore the attributes |
ignoreNameSpace |
Boolean, whether to ignore the namespaces |
parseNodeValue |
Boolean, whether to parse the node values to numbers if possible |
parseAttributeValue |
Boolean, whether to parse the attribute values to numbers if possible |
trimValues |
Boolean, whether to trim the values |
A JSON string.
xml <- system.file("extdata", "order-schema.xml", package = "xml2")
cat(xml2json(xml))
#
js <- c(
'if(key === "@_type"){',
' return undefined;',
'} else if(key === "@_name"){',
' return value.toUpperCase();',
'}',
'return value;'
)
cat(xml2json(xml, linebreaks = TRUE, replacer = js))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.