| xml_children {xml2} | R Documentation |
xml_children returns only elements, xml_contents returns
all nodes. xml_length returns the number of children.
xml_parent returns the parent node, xml_parents
returns all parents up to the root. xml_siblings returns all nodes
at the same level.
xml_children(x) xml_contents(x) xml_parents(x) xml_siblings(x) xml_parent(x) xml_length(x, only_elements = TRUE)
x |
A document, node, or node set. |
only_elements |
For |
A node or nodeset (possibly empty). Results are always de-duplicated.
x <- read_xml("<foo> <bar><boo /></bar> <baz/> </foo>")
xml_children(x)
xml_children(xml_children(x))
xml_siblings(xml_children(x)[[1]])
# Note the each unique node only appears once in the output
xml_parent(xml_children(x))
# Mixed content
x <- read_xml("<foo> a <b/> c <d>e</d> f</foo>")
# Childen gets the elements, contents gets all node types
xml_children(x)
xml_contents(x)
xml_length(x)
xml_length(x, only_elements = FALSE)