You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

185 lines
8.5 KiB

<!-- Generated by pkgdown: do not edit by hand -->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>xml_view. htmltidy</title>
<!-- jquery -->
<script src="https://code.jquery.com/jquery-3.1.0.min.js" integrity="sha384-nrOSfDHtoPMzJHjVTdCopGqIqeYETSXhZDFyniQ8ZHcVy08QesyHcnOUpMpqnmWq" crossorigin="anonymous"></script>
<!-- Bootstrap -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<!-- Font Awesome icons -->
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-T8Gy5hrqNKT+hzMclPo118YTQO6cYprQmhrYwIiQ/3axmI1hQomh7Ud2hPOy8SP1" crossorigin="anonymous">
<!-- pkgdown -->
<link href="../pkgdown.css" rel="stylesheet">
<script src="../pkgdown.js"></script>
<!-- mathjax -->
<script src='https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script>
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container">
<header>
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="../index.html">htmltidy</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>
<a href="../index.html">Home</a>
</li>
<li>
<a href="../reference/index.html">Reference</a>
</li>
<li>
<a href="../news/index.html">News</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
<a href="https://github.com/hrbrmstr/htmltidy">
<span class="fa fa-github fa-lg"></span>
</a>
</li>
</ul>
</div><!--/.nav-collapse -->
</div><!--/.container -->
</div><!--/.navbar -->
</header>
<div class="page-header">
<h1>HTML/XML pretty printer and viewer</h1>
</div>
<div class="row">
<div class="col-md-9">
<p>This uses the <code>vkbeautify</code> and <code>highlight.js</code> javascript modules to format and
&quot;pretty print&quot; HTML/XML documents, nodes, node sets and plain character
HTML/XML in an <code>htmlwidget</code> pane.</p>
<pre><span class='fu'>xml_view</span>(<span class='no'>doc</span>, <span class='kw'>style</span> <span class='kw'>=</span> <span class='st'>"default"</span>, <span class='kw'>scroll</span> <span class='kw'>=</span> <span class='fl'>FALSE</span>, <span class='kw'>add_filter</span> <span class='kw'>=</span> <span class='fl'>FALSE</span>,
<span class='kw'>apply_xpath</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>elementId</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>width</span> <span class='kw'>=</span> <span class='st'>"100%"</span>, <span class='kw'>height</span> <span class='kw'>=</span> <span class='kw'>NULL</span>)
<span class='fu'>html_view</span>(<span class='no'>doc</span>, <span class='kw'>style</span> <span class='kw'>=</span> <span class='st'>"default"</span>, <span class='kw'>scroll</span> <span class='kw'>=</span> <span class='fl'>FALSE</span>, <span class='kw'>add_filter</span> <span class='kw'>=</span> <span class='fl'>FALSE</span>,
<span class='kw'>apply_xpath</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>elementId</span> <span class='kw'>=</span> <span class='kw'>NULL</span>, <span class='kw'>width</span> <span class='kw'>=</span> <span class='st'>"100%"</span>, <span class='kw'>height</span> <span class='kw'>=</span> <span class='kw'>NULL</span>)</pre>
<h2>Arguments</h2>
<dl class="dl-horizontal">
<dt>doc</dt>
<dd><code>xml2</code> document/node/nodeset, an <code>HTMLInternalDocument</code>/
<code>XMLInternalDocument</code> or atomic character vector of HTML/XML content</dd>
<dt>style</dt>
<dd>CSS stylesheet to use (see <code>higlight_styles()</code>)</dd>
<dt>scroll</dt>
<dd>should the <code>&lt;div&gt;</code> holding the HTML/XML content scroll
(<code>TRUE</code>) or take up the full viewer/browser window (<code>FALSE</code>).
Default is <code>FALSE</code> (take up the full viewer/browser window). If
this is set to <code>TRUE</code>, <code>height</code> should be set to a value
other than <code>NULL</code>.</dd>
<dt>add_filter</dt>
<dd>show an XPath input box to enable live filtering?
(default: <code>FALSE</code>)</dd>
<dt>apply_xpath</dt>
<dd>Add and apply an XPath query string to the view. If
<code>add_filter</code> is <code>TRUE</code> then this query string will
appear in the filter box and be applied to the passed in document.</dd>
<dt>elementId</dt>
<dd>element id</dd>
<dt>width</dt>
<dd>widget width (best to keep it at 100%)</dd>
<dt>height</dt>
<dd>widget height (kinda only useful for knitting since this is
meant to be an interactive tool).</dd>
</dl>
<div class="Note">
<h2>Note</h2>
<p>Large HTML or XML content may take some time to render properly. It is suggested
that this function be used on as minimal of a subset of HTML/XML as possible
or used in a browser context vs an IDE viewer context.</p>
</div>
<div class="References">
<h2>References</h2>
<p><a href = 'highlight.js'>https://highlightjs.org/</a>,
<a href = 'vkbeautify'>http://www.eslinstructor.net/vkbeautify/</a></p>
</div>
<h2 id="examples">Examples</h2>
<pre class="examples"><div class='input'><span class='co'>## Not run: ------------------------------------</span>
<span class='co'># library(xml2)</span>
<span class='co'># </span>
<span class='co'># # plain text</span>
<span class='co'># txt &lt;- paste0("&lt;note&gt;&lt;to&gt;Tove&lt;/to&gt;&lt;from&gt;Jani&lt;/from&gt;&lt;heading&gt;Reminder&lt;/heading&gt;",</span>
<span class='co'># "&lt;body&gt;Don't forget me this weekend!&lt;/body&gt;&lt;/note&gt;")</span>
<span class='co'># xml_view(txt)</span>
<span class='co'># </span>
<span class='co'># # xml object</span>
<span class='co'># doc &lt;- read_xml(txt)</span>
<span class='co'># xml_view(doc, style="obsidian")</span>
<span class='co'># </span>
<span class='co'># # different style</span>
<span class='co'># xml_view(xml_find_all(doc, ".//to"), style="github-gist")</span>
<span class='co'># </span>
<span class='co'># # some more complex daata</span>
<span class='co'># xml_view(read_xml(system.file("extdata/dwml.xml", package="htmltidy")))</span>
<span class='co'># xml_view(read_xml(system.file("extdata/getHistory.xml", package="htmltidy")),</span>
<span class='co'># "androidstudio")</span>
<span class='co'># xml_view(read_xml(system.file("extdata/input.xml", package="htmltidy")),</span>
<span class='co'># "sunburst")</span>
<span class='co'># </span>
<span class='co'># # filter + apply an initial XPath query string</span>
<span class='co'># xml_view(read_xml(system.file("extdata/dwml.xml", package="xmlview")),</span>
<span class='co'># add_filter=TRUE, apply_xpath=".//temperature")</span>
<span class='co'># </span>
<span class='co'># doc &lt;- read_xml("http://www.npr.org/rss/rss.php?id=1001")</span>
<span class='co'># </span>
<span class='co'># str(doc)</span>
<span class='co'># </span>
<span class='co'># xml_view(doc, add_filter=TRUE)</span>
<span class='co'># xml2::xml_find_all(doc, './/dc:creator', ns=xml2::xml_ns(doc))</span>
<span class='co'># </span>
<span class='co'># xml_text(xml2::xml_find_all(doc, './/link[contains(., "soccer")]', ns=xml2::xml_ns(doc)))</span>
<span class='co'>## ---------------------------------------------</span></div></pre>
</div>
<div class="col-md-3">
</div>
</div>
<footer>
<p>Built by <a href="http://hadley.github.io/pkgdown/">pkgdown</a>. Styled with <a href="http://getbootstrap.com">Bootstrap 3</a>.</p>
</footer>
</div>
</body>
</html>