Skip to contents

Read XML File as Pairs of Paths and Values

Usage

read_xml_as_path_value(xml, dbg = TRUE, max_length = 100)

Arguments

xml

path, url or literal xml or anything else that is accepted by read_xml as argument x

dbg

if TRUE, debug messages are shown

max_length

maximum number of characters reserved for printing the path to the folder of the xml file in the debug message

Value

data frame with the full paths to the XML elements in the first and the text values of the XML elements in the second column.

Examples

url <- "https://www.w3schools.com/xml/note.xml"

# Original XML content
kwb.utils::catLines(readLines(url, warn = FALSE))
#> <?xml version="1.0" encoding="UTF-8"?>
#> <note>
#>   <to>Tove</to>
#>   <from>Jani</from>
#>   <heading>Reminder</heading>
#>   <body>Don't forget me this weekend!</body>
#> </note>

# Interpretation as Paths and Values
kwb.read:::read_xml_as_path_value(url)
#> Reading 'note.xml' in folder
#>   'https://www.w3schools.com/xml' ... ok.
#>            path                         value
#> 1      /note/to                          Tove
#> 2    /note/from                          Jani
#> 3 /note/heading                      Reminder
#> 4    /note/body Don't forget me this weekend!