Finds all XML elements in an XML document that lie on a certain path, regardless of where exactly the path is found in the XML document. Sub-elements (children) of the elements on the search path are returned, too.

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

## Arguments

xmlflat.df A flat XML dataframe created with fxml_importXMLFlat. 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"). 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 . 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.

## Value

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

## Details

With fxml_findPath() it does not matter where exactly in the hierarchy of the XML document the path is found. If, for example, path = c("tag1", "tag2") then the element with full XML path <xml><testdoc><tag1><tag2> would be found, too.

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

• fxml_findPathRoot: Search for path from the root node of the XML document downwards. Sub-elements are returned, too.

• fxml_findPathFull: Search for exact path (always starting from the root node). No sub-elements returned, as they have a different path than the search path.

• fxml_findPathBottom: Search for path from the bottom of the element hierarchy in the XML document.

fxml_findPathRoot, fxml_findPathFull, fxml_findPathBottom

## Examples

# 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 with <data><record><field> in their XML path
path <- c("data", "record", "field")
fxml_findPath(xml.dataframe, path)#>   [1]   4   5   6   7   8  10  11  12  13  14  16  17  18  19  20  22  23  24
#>  [19]  25  26  28  29  30  31  32  34  35  36  37  38  40  41  42  43  44  46
#>  [37]  47  48  49  50  52  53  54  55  56  58  59  60  61  62  64  65  66  67
#>  [55]  68  70  71  72  73  74  76  77  78  79  80  82  83  84  85  86  88  89
#>  [73]  90  91  92  94  95  96  97  98 100 101 102 103 104 106 107 108 109 110
#>  [91] 112 113 114 115 116 118 119 120 121 122 124 125 126 127 128 130 131 132
#> [109] 133 134 136 137 138 139 140 142 143 144 145 146 148 149 150 151 152
# Find only those XML elements with <data><record><field> in their XML path that have the
# "name" attribute of the <field> element set to "Sex"
path <- c("data", "record", "field")
fxml_findPath(xml.dataframe, path, attr.only = list(field = c(name = "Sex")))#>  [1]   6  12  18  24  30  36  42  48  54  60  66  72  78  84  90  96 102 108 114
#> [20] 120 126 132 138 144 150