Learn R Programming

openxlsx2 (version 0.7)

read_xml: read xml file

Description

read xml file

Usage

read_xml(
  xml,
  pointer = TRUE,
  escapes = FALSE,
  declaration = FALSE,
  whitespace = TRUE,
  empty_tags = FALSE,
  skip_control = TRUE
)

Arguments

xml

something to read character string or file

pointer

should a pointer be returned?

escapes

bool if characters like "&" should be escaped. The default is no escapes. Assuming that the input already provides valid information.

declaration

should the declaration be imported

whitespace

should whitespace pcdata be imported

empty_tags

should <b/> or <b></b> be returned

skip_control

should whitespace character be exported

Details

Read xml files or strings to pointer and checks if the input is valid XML. If the input is read into a character object, it will be reevaluated every time it is called. A pointer is evaluated once, but lives only for the lifetime of the R session or once it is gc().

Examples

Run this code
  # a pointer
  x <- read_xml("")
  print(x)
  print(x, raw = TRUE)
  str(x)

  # a character
  y <- read_xml("", pointer = FALSE)
  print(y)
  print(y, raw = TRUE)
  str(y)

  # Errors if the import was unsuccessful
  try(z <- read_xml(""))

  xml <- 'A & B'
  # difference in escapes
  read_xml(xml, escapes = TRUE, pointer = FALSE)
  read_xml(xml, escapes = FALSE, pointer = FALSE)
  read_xml(xml, escapes = TRUE)
  read_xml(xml, escapes = FALSE)

  # read declaration
  read_xml(xml, declaration = TRUE)

Run the code above in your browser using DataLab