XMLInternalElementNode
objects
and regular R-level XMLNode
objects. addChildren
is similar to addNode
and the two may be consolidated into a single generic
function and methods in the future.
addChildren(node, ..., kids = list(...), at = NA, cdata = FALSE, append = TRUE)
removeChildren(node, ..., kids = list(...), free = FALSE)
removeNodes(node, free = rep(FALSE, length(node)))
replaceNodes(oldNode, newNode, ...)
addAttributes(node, ..., .attrs = NULL,
suppressNamespaceWarning = getOption("suppressXMLNamespaceWarning", FALSE),
append = TRUE)
removeAttributes(node, ..., .attrs = NULL, .namespace = FALSE,
.all = (length(list(...)) + length(.attrs)) == 0)
kids
or .attrs
pnode
argument. However, they can also be
regular strings in which case they arr:length
and the namespaces will be resolved relative to the
list supported by node
to ensure tTRUE
means to free that memory.
This is only applicable for the internal nodes created
with x
oldNode
in the list of children of the parent of
oldNode
TRUE
) the specified
attributes or children should be added to the existing attributes on the XML node
(if any exist), or, if FALSE
these should replace any existing attributes.XMLNode
object, this is is an entirely
separate object from the original node.
It must be inserted back into its parent "node" or context if the changes are to be
seen in that wider context.xmlTree
newXMLNode
b = newXMLNode("bob", namespace = c(r = "http://www.r-project.org", omg = "http://www.omegahat.org"))
cat(saveXML(b), "")
addAttributes(b, a = 1, b = "xyz", "r:version" = "2.4.1", "omg:len" = 3)
cat(saveXML(b), "")
removeAttributes(b, "a", "r:version")
cat(saveXML(b), "")
removeAttributes(b, .attrs = names(xmlAttrs(b)))
addChildren(b, newXMLNode("el", "Red", "Blue", "Green",
attrs = c(lang ="en")))
k = lapply(letters, newXMLNode)
addChildren(b, kids = k)
cat(saveXML(b), "")
removeChildren(b, "a", "b", "c", "z")
# can mix numbers and names
removeChildren(b, 2, "e") # d and e
cat(saveXML(b), "")
i = xmlChildren(b)[[5]]
xmlName(i)
# have the identifiers
removeChildren(b, kids = c("m", "n", "q"))
x <- xmlNode("a",
xmlNode("b", "1"),
xmlNode("c", "1"),
"some basic text")
v = removeChildren(x, "b")
# remove c and b
v = removeChildren(x, "c", "b")
# remove the text and "c" leaving just b
v = removeChildren(x, 3, "c")
# this won't work as the 10 gets coerced to a
# character vector element to be combined with 'w'
# and there is no node name 10.
removeChildren(b, kids = c(10, "w"))
# for R-level nodes (not internal)
z = xmlNode("arg", attrs = c(default="TRUE"),
xmlNode("name", "foo"), xmlNode("defaultValue","1:10"))
o = addChildren(z,
"some text",
xmlNode("a", "a link", attrs = c(href = "http://www.omegahat.org/RSXML")))
o
# removing nodes
doc = xmlParse("<top><a/><b/><c><d/><e>bob</e></c></top>")
top = xmlRoot(doc)
top
removeNodes(list(top[[1]], top[[3]]))
# a and c have disappeared.
top
Run the code above in your browser using DataLab