xmlview : View formatted and "pretty printed" HTML/XML in R

(if you need JSON, \code{list} or general object viewing in R check out xmlview's sister package, jsonview)

It is intended for interactive use. When working with XML data, it's often times advantageous to be able to see the document and possibly even more advantageous to see the results of XPath or CSS selector slicing & dicing.

You can pass in:

and view the formatted & pretty-printed result in the RStudio viewer or web browser.

The widget uses vkbeautify, highlight.js and xml-viewer to do all the work.

The following functions are implemented:


Please devtools::install_github("ramnathv/htmlwidgets") for this as we're now using the more modern (and bleeding edge htmlwidgets functionality).


News

Installation

devtools::install_github("hrbrmstr/xmlview")
options(width=120)

Usage

library(xmlview)
library(xml2)

# available styles
highlight_styles()

# plain character
txt <- "<note><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend!</body></note>"

xml_view(txt)

# xml document
doc <- read_xml(txt)

xml_view(doc, style="obsidian")
xml_view(xml_find_all(doc, ".//to"), style="github-gist")

xml_view(read_xml(system.file("extdata/dwml.xml", package="xmlview")))
xml_view(read_xml(system.file("extdata/getHistory.xml", package="xmlview")), "androidstudio")
xml_view(read_xml(system.file("extdata/input.xml", package="xmlview")), "sunburst")

# SO: http://stackoverflow.com/questions/34664028/extract-xml-data-using-xmlsapply-in-r
doc <- read_xml("http://d396qusza40orc.cloudfront.net/getdata%2Fdata%2Frestaurants.xml")
xml_view(xml_find_all(doc, ".//*[contains(@_id, '7')]"), style="monokai_sublime")

Screen shot (plain viewer)

Screen recording of filtering

Here is the R code (it's a bit hard to read):

library(xml2)

doc <- read_xml("http://www.npr.org/rss/rss.php?id=1001")

str(doc)

xml_view(doc, add_filter=TRUE)

# The first copied code:
xml2::xml_find_all(doc, './/dc:creator', ns=xml2::xml_ns(doc))

# The second copied code:
xml_text(xml2::xml_find_all(doc, './/link[contains(., "soccer")]', ns=xml2::xml_ns(doc)))



hrbrmstr/xmlview documentation built on May 17, 2019, 5:54 p.m.