xml_fill_template: Title

Description Usage Arguments Value Examples

View source: R/xml_fill_tempate.R

Description

Title

Usage

1
2
xml_fill_template(xmltemplate, with, collapse = NULL, export = NULL,
  name = NULL)

Arguments

xmltemplate

a xml document to use as template

with

a dataframe with the values of elements to replace in xmltemplate. Colnames and text of elements to replace in xmltemplate must be equals.

collapse

if NULL (default) the function return a list of xml documents of length the number of rows in with. otherwse you can specify a root name to collapse all new xml documents in one. If the given root name is also the root name of xmltemplate, the latter root must have only one children node.

export

a string giving the path to the folder where the xml files are exported. If NULL (default), nothing is exported

name

optional. Only if export is not NULL, either a single string with the name of the exported file or a vector of strings with the names of all the exported xml files. Length of name must be either 1 or equal to the rows number of with

Value

either a list of length nrow(with) where each element is a new xml document or only one new xml document if collapse!=NULL

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
library(xml2)
template <- read_xml("<parent><child nom=\"child1\"><grandchild>grandchild1</grandchild>
<grandchild>grandchild2</grandchild></child><child nom=\"child2\">null</child></parent>")
toreplace <- data.frame(child1 = c("Ben1", "Ben2"), child2 = c("Sarah1", "Sarah2"),
grandchild1 = c("Brad1", "Brad2"), grandchild2 = c("Jude1", "jude2"))

# No export, no collapsing
newxml <- xml_fill_template(template, toreplace)

# Export and collapsing
## Not run: 
newxml <- xml_fill_template(template, toreplace, collapse = "grandparent",
export = getwd(), name = "testexport")

## End(Not run)

BenjaminLouis/xmlprocessor documentation built on May 27, 2019, 3:28 p.m.