fxml_findPathBottom: Finding XML elements

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/flatxml.r

Description

Finds all XML elements in an XML document that lie on a certain path. The path of the found elements must end with the provided search path.

Usage

1
fxml_findPathBottom(xmlflat.df, path, attr.only = NULL, attr.not = NULL)

Arguments

xmlflat.df

A flat XML dataframe created with fxml_importXMLFlat.

path

A character vector representing the path to be searched. Each element of the vector is a hierarchy level in the XML document. Example: path = c("tag1", "tag2").

attr.only

A list of named vectors representing attribute/value combinations the XML elements on the search path must match. The name of an element in the list is the XML elment name to which the attribute belongs. The list element itself is a named vector. The vector's elements represent different attributes (= the names of the vector elements) and their values (= vector elements). Example: attr.only = list(tag1 = c(attrib1 = "Value 1", attrib2 = "Value 2"), tag2 = c(attrib3 = "Value 3")) will only find those elements which lie on a path that includes <tag1 attrib1 = "Value 1" attrib2 = "Value 2"><tag2 attrib3 = "Value 3">.

attr.not

A list of vectors representing attribute/value combinations the XML elements on the search path must not match to be included in the results. See argument attr.only for details on the composition.

Details

With fxml_findPathRoot(), the search always starts at the bottom of the element hierarchy of the XML document. Only if the path of an elemends ends with the provided search path, it is returned as a result. If, for example, path = c("tag1", "tag2") then the element with full XML path <tag1><tag2><tag3> would not be found, only if search path were c("tag2", "tag3").

Other fxml_findPath...() functions allow for different search modes:

Value

The IDs (xmlflat.df$elemid.) of the XML elements that are located on the provided path. NULL, if no elements where found.

Author(s)

Joachim Zuckarelli [email protected]

See Also

fxml_findPath, fxml_findPathRoot, fxml_findPathFull

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# Load example file with population data from United Nations Statistics Division
# and create flat dataframe
example <- system.file("worldpopulation.xml", package="flatxml")
xml.dataframe <- fxml_importXMLFlat(example)

# Find all XML elements that have a path ending with <record><field>
path <- c("record", "field")
fxml_findPathBottom(xml.dataframe, path)

# Find all XML elements that have a path ending with <record><field>, but only
# those which have the "name" attribute of the <field> element set to "Sex"
path <- c("record", "field")
fxml_findPathBottom(xml.dataframe, path, attr.only = list(field = c(name = "Sex")))

jsugarelli/flatxml documentation built on Aug. 7, 2018, 3:31 p.m.