Move from nodes to related nodes. Operations that return exactly one
node per input node – html_parent(), html_next_sibling() and
html_previous_sibling() – are aligned: the result has the same
length as x, with a missing node where there is no answer, so that
results line up with their inputs. Operations that can return many nodes
per input – html_children(), html_ancestors() and
html_template_content() – return the set of all results, without
duplicates, in document order.
Usage
html_children(x, elements_only = TRUE)
html_parent(x)
html_ancestors(x)
html_next_sibling(x, elements_only = TRUE)
html_previous_sibling(x, elements_only = TRUE)
html_template_content(x)
html_root(x)
html_document(x)Value
html_children(),html_ancestors(),html_template_content(): azuhtml_nodesetin document order.html_ancestors()does not include the document node.html_parent(),html_next_sibling(),html_previous_sibling(): azuhtml_nodesetas long asx, with missing nodes where there is no parent or sibling.html_root(): azuhtml_nodesetof length one: the<html>element of a document, or the fragment node of a fragment.html_document(): thezuhtml_documentthat ownsx.
Details
A <template> element's contents are its children here, but they are
inert: searches and text extraction do not descend into them.
html_template_content() returns them explicitly.
See also
Other navigation:
html_closest(),
html_elements()
Examples
doc <- html_parse("<ul><li>One</li><li>Two <b>bold</b></li></ul>")
body <- html_children(html_root(doc))[2]
items <- html_children(html_children(body))
items
#> <zuhtml_nodeset[2]>
#> [1] <li>
#> [2] <li>
html_parent(items)
#> <zuhtml_nodeset[2]>
#> [1] <ul>
#> [2] <ul>
html_next_sibling(items)
#> <zuhtml_nodeset[2]>
#> [1] <li>
#> [2] <missing>
html_ancestors(html_children(items[2]))
#> <zuhtml_nodeset[4]>
#> [1] <html>
#> [2] <body>
#> [3] <ul>
#> [4] <li>
# Template contents are reached explicitly:
tmpl <- html_parse("<template><p>inert</p></template>")
html_template_content(html_children(html_children(html_root(tmpl))[1]))
#> <zuhtml_nodeset[1]>
#> [1] <p>