Learn R Programming

rvest (version 0.2.0)

xml: Work with xml.

Description

All methods work the same as their HTML equivalents. Currently xml parses XML files as HTML because I can't find another way to ignore namespaces.

Usage

xml(x, ..., encoding = NULL)

xml_tag(x)

xml_attr(x, name, default = NA_character_)

xml_attrs(x)

xml_node(x, css, xpath)

xml_nodes(x, css, xpath)

xml_text(x, ...)

xml_children(x)

Arguments

x
A url, a local path, a string containing html, or a response from an httr request.
...
If x is a URL, additional arguments are passed on to GET().
encoding
Specify encoding of document. See iconvlist() for complete list. If you have problems determining the correct encoding, try stri_enc_detect
name
Name of attribute to extract.
default
A string used as a default value when the attribute does not exist in every node.
css
Nodes to select. Supply one of css or xpath depending on whether you want to use a css or xpath selector.
xpath
Nodes to select. Supply one of css or xpath depending on whether you want to use a css or xpath selector.

Examples

Run this code
search <- xml("http://stackoverflow.com/feeds")

entries <- search %>% xml_nodes("entry")
entries[[1]] %>% xml_structure()

entries %>% xml_node("author name") %>% xml_text()
entries %>% lapply(. %>% xml_nodes("category") %>% xml_attr("term"))

Run the code above in your browser using DataLab