df_to_xml {xmlconvert} | R Documentation |
Converting XML to data frames and vice versa
Description
Converts dataframes to XML documents.
Usage
df_to_xml(
df,
fields = "tags",
record.tag = "record",
field.names = NULL,
only.fields = NULL,
exclude.fields = NULL,
root.node = "root",
xml.file = NULL,
non.exist = NULL,
encoding = "UTF-8",
no.return = FALSE
)
Arguments
df |
Dataframe to be converted to XML |
fields |
A character value, either |
record.tag |
Name of the tags that will represent the data records in the resulting XML (i.e. each record has one element with this tag name). |
field.names |
Names of the fields in the XML file. If |
only.fields |
Optional vector variable names from the dataframe that
will be included in the XML document. If |
exclude.fields |
Optional vector of variable names from the dataframe that will not be included in the XML document. |
root.node |
A character value with the desired name of the root element
of the XML document; |
xml.file |
Name of a file the XML document it written to. If |
non.exist |
Value that will be written into the XML document as field
value in case the respective element in the dataframe is |
encoding |
Encoding of the XML document; default is |
no.return |
Logical option to prevent |
Value
The resulting XML document that be edited with the functions from the
xml2 package. There is no return value if the no.return
argument is set to TRUE
.
See Also
Other xmlconvert:
xml_to_df()
Examples
# Create a dataframe
soccer.worldcups <- data.frame(list(year=c(2014, 2010, 2006),
location=c("Brazil", "South Africa", "Germany"),
goals_scored=c(171, 145, 147),
average_goals=c(2.7, 2.3, 2.4),
average_attendance=c(57918, 49669,52491)),
stringsAsFactors = FALSE)
# Convert to XML with the fields (i.e. dataframe variables/columns) stored in XML tags
xml <- df_to_xml(soccer.worldcups, fields="tags", record.tag = "worldcup")
# Convert to XML with the fields (i.e. dataframe variables/columns) stored in attributes
xml <- df_to_xml(soccer.worldcups, fields="tags", record.tag = "worldcup")