xml_get_text: Get XML Text.

Description Usage Arguments Details Value Examples

Description

Return an XML text value if provided the document and Xpath.

Usage

1
xml_get_text(x, xpath)

Arguments

x

XML document: a literal XML document, a URL, or a string.

xpath

A string containing a xpath (1.0) expression.

Details

Serves as a convenience function. Utilizes xml_find_first and xml_text and will return NA_character_ if the XML text cannot be located or an error occurs.

Because the function uses xml_find_first, only the first match is returned.

Value

XML text as a string or NA_character_ if an error occurs.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
xml_doc <- "
<root_tag>
  <another_tag>
    <var_text>10</var_text>
    <var_attr value=\"10\"></var_attr>
  </another_tag>
</root_tag>
"

ten <- xml_get_text(xml_doc,
                    "//root_tag/another_tag/var_text")
identical(ten, "10")

curtisalexander/CRAmisc documentation built on May 14, 2019, 12:52 p.m.