Description Usage Arguments Details Value Examples
Return an XML node attribute if provided the document, XPath, and attribute name.
1 | xml_get_attr(x, xpath, extract_value)
|
x |
XML document: a literal XML document, a URL, or a string |
xpath |
A string containing a xpath (1.0) expression. |
extract_value |
A string containing the attribute name to extract. |
Serves as a convenience function. Utilizes xml_find_first
and xml_attr and will return NA_character_
if the XML
attribute cannot be located or an error occurs.
Because the function uses xml_find_first, only the first match is returned.
XML node attribute as a string or NA_character_
if an error
occurs.
1 2 3 4 5 6 7 8 9 10 11 12 13 | xml_doc <- "
<root_tag>
<another_tag>
<var_text>10</var_text>
<var_attr value=\"10\"></var_attr>
</another_tag>
</root_tag>
"
ten <- xml_get_attr(xml_doc,
"//root_tag/another_tag/var_attr",
"value")
identical(ten, "10")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.