pasteXMLTag: Write an XML tag

Description Usage Arguments Value Note See Also Examples

View source: R/pasteXMLTag.R

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

1
2
3
pasteXMLTag(tag, attr = NULL, child = NULL, empty = TRUE, level = 1,
  allow.empty = FALSE, rename = NULL, shine = 2, indent.by = "\t",
  tidy = TRUE)

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.

Value

A character string.

Note

However, you will probably not want to use this function at all, as it is much more comfortable to create XML nodes or even nested trees with XMLNode and XMLTree, and then feed the result to pasteXML.

See Also

XMLNode, XMLTree, pasteXML

Examples

1
2
3
4
sample.XML.tag <- pasteXMLTag("a",
  attr=list(href="http://example.com", target="_blank"),
  child="klick here!",
  empty=FALSE)

rkward-community/XiMpLe documentation built on Dec. 13, 2017, 10:11 p.m.