xml_replace_values: Replace values in a xml template document

Description Usage Arguments Value Examples

View source: R/xml_replace_values.R

Description

Replace values in a xml template document

Usage

1
xml_replace_values(xml, replacement)

Arguments

xml

a xml document read with read_xml

replacement

one of a one row dataframe, a named list or a named vector where (col)names correspond to the values to replace in the xml template and the elements are the values to replace with

Value

a new xml document with changes applied to the xml template

Examples

1
2
3
4
5
library(xml2)
template <- read_xml("<parent><child nom=\"child1\"><grandchild>grandchild1</grandchild>
<grandchild>grandchild2</grandchild></child><child nom=\"child2\">null</child></parent>")
toreplace <- c(child1 = "Ben", child2 = "Sarah", grandchild1 = "Brad", grandchild2 = "Jude")
newxml <- xml_replace_values(xml = template, replacement = toreplace)

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