xml_children {xml2} | R Documentation |
Navigate around the family tree.
Description
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_child
makes it easy to specify a specific
child to return.
Usage
xml_children(x)
xml_child(x, search = 1, ns = xml_ns(x))
xml_contents(x)
xml_parents(x)
xml_siblings(x)
xml_parent(x)
xml_length(x, only_elements = TRUE)
xml_root(x)
Arguments
x |
A document, node, or node set. |
search |
For |
ns |
Optionally, a named vector giving prefix-url pairs, as produced
by |
only_elements |
For |
Value
A node or nodeset (possibly empty). Results are always de-duplicated.
Examples
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)
# xml_child makes it easier to select specific children
xml_child(x)
xml_child(x, 2)
xml_child(x, "baz")