Creates a whole XML tag with attributes and, if it is a pair of start and end tags, also one object as child. This can be used recursively to create whole XML tree structures with this one function.
pasteXMLTag(
tag,
attr = NULL,
child = NULL,
empty = TRUE,
level = 1,
allow.empty = FALSE,
rename = NULL,
shine = 2,
indent.by = getOption("XiMpLe_indent", "\t"),
tidy = TRUE,
as_script = FALSE,
func_name = paste0(tag, "_"),
func_rename = c(`?xml_` = "xml_", `!--_` = "comment_", `![CDATA[_` = "CDATA_",
`!DOCTYPE_` = "DOCTYPE_")
)
A character string.
Character string, name of the XML tag.
A list of attributes for the tag.
If empty=FALSE
,
a character string to be pasted as a child node between start and end tag.
Logical, <true /> or <false></false>
Indentation level.
Logical, if FALSE
,
tags without attributes will not be returned.
An optional named list if the attributes in XML need to be renamed from their list names in attr
.
This list must in turn have a list element named after tag
,
containing named character elements, where the
names represent the element names in attr
and their values the names the XML attribute should get.
Integer, controlling if the output should be formatted for better readability. Possible values:
No formatting.
Nodes will be indented.
Nodes will be indented and each attribute gets a new line.
A charachter string defining how indentation should be done. Defaults to tab.
Logical, if TRUE
the special characters "<",
">" and "&" will be replaced with the entities
"<", ">" and "&" in attribute values. For comment or CDATA tags,
if the text includes newline characters
they will also be indented.
Logical, if TRUE
,
tags will be pasted as a sketch for a script to be run in conjunction with
functions generated by gen_tag_functions
. This script code will most
likely not run without adjustments, but is perhaps a good start anyway.
A character string,
defining a function name for tag
. Only used when as_script=TRUE
.
Named character vector defining which tags' functions should get a different name.
This makes it easier to get functions with valid names that generate special tag nodes.
Only used when as_script=TRUE
. Use the same names and values as you used in
gen_tag_functions
.
XMLNode
,
XMLTree
,
pasteXML
sample.XML.tag <- pasteXMLTag("a",
attr=list(href="http://example.com", target="_blank"),
child="klick here!",
empty=FALSE)
Run the code above in your browser using DataLab