xml_view: XML pretty printer & viewer

Description Usage Arguments References Examples

View source: R/xmlview.R

Description

This uses vkbeautify and highlight.js to format and "pretty print" HTML/XML documents, nodes, node sets and plain character HTML/XML in an htmlwidget pane.

Usage

1
2
xml_view(doc, style = "default", scroll = FALSE, add_filter = FALSE,
  apply_xpath = NULL, elementId = NULL, width = "100%", height = NULL)

Arguments

doc

xml2 document, node, nodeset or atomic character vector of HTML/XML content

style

CSS stylesheet to use (see higlight_styles())

scroll

should the <div> holding the HTML/XML content scroll (TRUE) or take up the full viewer/browser window (FALSE). Default is FALSE (take up the full viewer/browser window). If this is set to TRUE, height should be set to a value other than NULL.

add_filter

show an XPath input box to enable live filtering? (default: FALSE)

apply_xpath

Add and apply an XPath query string to the view. If add_filter is TRUE then this query string will appear in the filter box and be applied to the passed in document.

elementId

element id

width

widget width (best to keep it at 100%)

height

widget height (kinda only useful for knitting since this is meant to be an interactive tool).

References

highlight.js, vkbeautify

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
library(xml2)

# plain text
txt <- paste0("<note><to>Tove</to><from>Jani</from><heading>Reminder</heading>",
              "<body>Don't forget me this weekend!</body></note>")
xml_view(txt)

# xml object
doc <- read_xml(txt)
xml_view(doc, style="obsidian")

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

# some more complex daata
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")

# filter + apply an initial XPath query string
xml_view(read_xml(system.file("extdata/dwml.xml", package="xmlview")),
         add_filter=TRUE, apply_xpath=".//temperature")

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