xmlElementsByTagName(el, name, recursive = FALSE)
el
's children.
el
and return a list with the nodes having the given name.
The relationship between the nodes in the resulting list
cannot be determined. This is a set of nodes. See the note.
This does a simple matching of names and subsets the XML node's
children list.
If
recursive=TRUE
, then it is also applied recursively to
the children of the given node, the childrens' children, etc.
el
whose
tag name matches that specified by the user.
The addition of the
recursive
argument makes this
function behave like the getElementsByTagName
in other language APIs such as Java and C.
However, one should be careful to understand that
in those languages, one would get back a set of
node objects. These nodes have references to their
parents and children. Therefore one can navigate the
tree from each node, find its relations, etc.
In the current version of this package (and for the forseeable
future), the node set is a copy of the
nodes in the original tree. And these have no facilities
for finding their siblings or parent.
Additionally, one can consume a large amount of memory by taking
a copy of numerous large nodes using this facility.
If one does not modify the nodes, the extra memory may be small. But
modifying them means that the contents will be copied.
Alternative implementations of the tree, e.g. using unique identifiers
for nodes or via internal data structures from libxml can allow us to
implement this function with different semantics, more similar to
the other APIs.
Duncan Temple Lang
http://www.w3.org/XML, http://www.omegahat.org/RSXML,
doc <- xmlTreeParse(system.file("exampleData", "mtcars.xml", package="XML")) xmlElementsByTagName(xmlRoot(doc)[[1]], "variable")