xmlr: xmlr

xmlrR Documentation

xmlr

Description

A package for creating, reading and manipulating XML providing and object model implemented with Reference Classes. This is perhaps especially useful when dealing with deeply nested XML structures.

Examples

library("xmlr")
doc <- Document$new()
root <- Element$new("table")
root$setAttribute("xmlns", "http://www.w3.org/TR/html4/")
doc$setRootElement(root)

root$addContent(
  Element$new("tr")
    $addContent(Element$new("td")$setText("Apples"))
    $addContent(Element$new("td")$setText("Bananas"))
)
table <- doc$getRootElement()
stopifnot(table$getName() == "table")
stopifnot(table$getAttribute("xmlns") == "http://www.w3.org/TR/html4/")

children <- table$getChild("tr")$getChildren()
stopifnot(length(children) == 2)
stopifnot(children[[1]]$getText() == "Apples")
stopifnot(children[[2]]$getText() == "Bananas")

# you can also parse character strings (or parse a file using parse.xmlfile(fileName))
doc <- parse.xmlstring("<foo><bar><baz val='the baz attribute'/></bar></foo>")

Alipsa/rcdom documentation built on March 27, 2022, 11:07 p.m.