Create a tag fragment with optional text and attributes
Usage
tag(tag, text = NULL, ..., .attr = list(...))
Examples
tag("greeting", "hi", id = "hi")
#> {xml_fragment}
#> <greeting id="hi">hi</greeting>
tag("person", id = "1") / (tag("name", "John Doe") + tag("age", 35))
#> {xml_fragment}
#> <person id="1">
#> <name>John Doe</name>
#> <age>35</age>
#> </person>
xml_fragment(person = frag(
.attr = c(id = 1),
name = "John Doe",
age = 30
)) / tag("address", "Unknown")
#> {xml_fragment}
#> <person id="1">
#> <name>John Doe</name>
#> <age>30</age>
#> <address>Unknown</addr...
a <- tag("person", id = 1) /
xml_fragment(
name ="John Doe",
age = 30,
address = frag(
street = "123 Main St",
city = "Springfield"
)
)
cat(as.character(a))
#> <person id="1">
#> <name>John Doe</name>
#> <age>30</age>
#> <address>
#> <street>123 Main St</street>
#> <city>Springfield</city>
#> </address>
#> </person>