Learn R Programming

XiMpLe (version 0.11-3)

pasteXMLTag: Write an XML tag

Description

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.

Usage

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_")
)

Value

A character string.

Arguments

tag

Character string, name of the XML tag.

attr

A list of attributes for the tag.

child

If empty=FALSE, a character string to be pasted as a child node between start and end tag.

empty

Logical, <true /> or <false></false>

level

Indentation level.

allow.empty

Logical, if FALSE, tags without attributes will not be returned.

rename

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.

shine

Integer, controlling if the output should be formatted for better readability. Possible values:

0

No formatting.

1

Nodes will be indented.

2

Nodes will be indented and each attribute gets a new line.

indent.by

A charachter string defining how indentation should be done. Defaults to tab.

tidy

Logical, if TRUE the special characters "<", ">" and "&" will be replaced with the entities "&lt;", "&gt;" and "&amp;" in attribute values. For comment or CDATA tags, if the text includes newline characters they will also be indented.

as_script

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.

func_name

A character string, defining a function name for tag. Only used when as_script=TRUE.

func_rename

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.

See Also

XMLNode, XMLTree, pasteXML

Examples

Run this code
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