Learn R Programming

mclm (version 0.2.7)

find_xpath: Run XPath query

Description

This function finds matches for an XPath query in a corpus.

Usage

find_xpath(x, pattern, fun = NULL, final_fun = NULL, namespaces = NULL, ...)

Value

A nodeset or the output of applying fun to a nodeset.

Arguments

x

A corpus: an fnames object, a character vector of an XML source, or a document parsed with xml2::read_xml().

pattern

An XPath query.

fun

Function to be applied to the individual nodes prior to returning the result.

final_fun

Function to be applied to the complete list of matches prior to returning the result.

namespaces

A namespace as generated by xml2::xml_ns().

...

Additional arguments.

Examples

Run this code
test_xml <- '

  The
  example
  .
'

find_xpath(test_xml, "//w")
find_xpath(test_xml, "//@pos")
find_xpath(test_xml, "//w[@pos='nn']")

find_xpath(test_xml, "//w", fun = xml2::xml_text)
find_xpath(test_xml, "//w", fun = xml2::xml_attr, attr = "pos")

Run the code above in your browser using DataLab