This recursively applies the specified function to each node in an
XML tree, creating a new tree,
parallel to the original input tree.
Each element in the new tree is the return
value obtained from invoking the specified function
on the corresponding element
of the original tree.
The order in which the function is recursively applied
is "bottom-up". In other words,
function is first applied to each of the children
nodes first and then to the parent node
containing the newly computed results for the children.
USAGE:
xmlDOMApply(dom, func)
ARGUMENTS:
dom
a node in the XML tree or DOM on which to recursively
apply the given function.
This should not be the
XMLDocument
itself returned from
but an object of class
XMLNode.
This is typically obtained by
calling
on the
return value from
.
func
the function to be applied to each node in the XML tree.
This is passed the node object for the and the return
value is inserted into the new tree that is to be returned
in the corresponding position as the node being processed.
If the return value is
NULL, this node is dropped from the tree.
DETAILS:
This is a native (C code) implementation that
understands the structure of an XML DOM returned
from
and iterates
over the nodes in that tree.
VALUE:
A tree that parallels the structure in the
dom
object passed to it.
dom <- xmlTreeParse(system.file("exampleData", "mtcars.xml", package="XML"))
fun <- function(x) {
# drop the attributes - just keep node name and children
lst <- c(list(xmlName(x)), xmlChildren(x))
if(inherits(x, "XMLTextNode")) x
else do.call("xmlNode", lst)
}
xmlDOMApply(xmlRoot(dom), fun)