xml_find_attr: Retrieve an attribute from the first node that matches an...

Description Usage Arguments Value Examples

View source: R/xml.R

Description

This is a helper function that uses xml_find_first to retrieve a node and then retrieves the specified attribute on that node.

Usage

1
xml_find_attr(x, xpath, attr, ns = xml_ns(x))

Arguments

x

A document, node or node set

xpath

A string containing a xpath (1.0) expression

attr

Name of attribute to extract

ns

Optionally, a named vector giving prefix-url pairs, as produced by xml_ns(). If provided, all names will be explicitly qualified with the ns prefix, i.e. if the element bar is defined in namespace foo, it will be called foo:bar. (And similarly for attributes). Default namespaces must be given an explicit name. The ns is ignored when using xml_name<-() and xml_set_name().

Value

A character vector. NA is used to represent of attributes that aren't defined.

Examples

1
2
x <- xml2::read_xml("<a id='foo' />")
xml_find_attr(x, "/a", "id")

tobiasziegler/aecfeedr documentation built on April 9, 2021, 10:45 a.m.