#' XML tree viewer
#'
#' This uses \code{xml-viewer} to provide a simple collapsible
#' tree viewer for HTML/XML documents, nodes, node sets and plain character
#' HTML/XML in an \code{htmlwidget} pane.
#'
#' @param doc \code{xml2} document, node, nodeset or atomic character vector
#' of HTML/XML content
#' @param scroll should the \code{<div>} holding the HTML/XML content scroll
#' (\code{TRUE}) or take up the full viewer/browser window (\code{FALSE}).
#' Default is \code{FALSE} (take up the full viewer/browser window). If
#' this is set to \code{TRUE}, \code{height} should be set to a value
#' other than \code{NULL}.
#' @param elementId element id
#' @param width widget \code{div} width
#' @param height widget \code{div} height
#' @export
#' @references \href{https://github.com/juliangruber/xml-viewer}{xml-viewer}
#' @example inst/examples/examples-xml_tree_view.R
xml_tree_view <- function(doc=NULL, scroll=FALSE,
elementId=NULL, width="100%", height=NULL) {
if (inherits(doc, "character")) {
doc <- paste0(doc, collapse="")
} else if (inherits(doc, "xml_nodeset")) {
doc <- paste0(as.character(doc), collapse="")
} else if (inherits(doc, "xml_document") | inherits(doc, "xml_node")) {
doc <- as.character(doc)
}
params <- list(
xmlDoc = doc,
scroll = scroll
)
# create widget
htmlwidgets::createWidget(
name = 'xmltreeview',
x = params,
width = width,
height = height,
package = 'xmlview',
elementId = elementId
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.