Learn R Programming

xml2 (version 0.1.0)

xml_children: Navigate around the family tree.

Description

xml_children returns only elements, xml_contents returns all nodes. xml_parent returns the parent node, xml_parents returns all parents up to the root. xml_siblings returns all nodes at the same level.

Usage

xml_children(x)

xml_contents(x)

xml_parents(x)

xml_siblings(x)

xml_parent(x)

Arguments

x
A document, node, or node set.

Value

  • A node or nodeset (possibly empty). Results are always de-duplicated.

Examples

Run this code
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)

Run the code above in your browser using DataLab