xml2json {cppcheckR} | R Documentation |
XML to JSON
Description
Convert XML to a JSON string.
Usage
xml2json(
xml,
spaces = 2L,
linebreaks = FALSE,
replacer = NULL,
attributeNamePrefix = "@_",
textNodeName = "#text",
ignoreAttributes = FALSE,
ignoreNameSpace = FALSE,
parseNodeValue = TRUE,
parseAttributeValue = TRUE,
trimValues = TRUE
)
Arguments
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 |
Value
A JSON string.
Examples
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))
[Package cppcheckR version 1.0.0 Index]