write_xml: Write XML or HTML to disk.

Description Usage Arguments Examples

View source: R/xml_write.R

Description

This writes out both XML and normalised HTML. The default behavior will output the same format which was read. If you want to force output pass option = "as_xml" or option = "as_html" respectively.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
write_xml(x, file, ...)

## S3 method for class 'xml_document'
write_xml(x, file, ..., options = "format",
  encoding = "UTF-8")

write_html(x, file, ...)

## S3 method for class 'xml_document'
write_html(x, file, ..., options = "format",
  encoding = "UTF-8")

Arguments

x

A document or node to write to disk. It's not possible to save nodesets containing more than one node.

file

Path to file or connection to write to.

...

additional arguments passed to methods.

options

default: ‘format’. Zero or more of \Sexpr[results=rd]{xml2:::describe_options(xml2:::xml_save_options())}

encoding

The character encoding to use in the document. The default encoding is ‘UTF-8’. Available encodings are specified at http://xmlsoft.org/html/libxml-encoding.html#xmlCharEncoding.

Examples

1
2
3
4
5
6
7
8
9
h <- read_html("<p>Hi!</p>")

tmp <- tempfile(fileext = ".xml")
write_xml(h, tmp, options = "format")
readLines(tmp)

# write formatted HTML output
write_html(h, tmp, options = "format")
readLines(tmp)

Example output

[1] "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">"
[2] "<html><body><p>Hi!</p></body></html>"                                                                          
[1] "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">"
[2] "<html><body><p>Hi!</p></body></html>"                                                                          

xml2 documentation built on Jan. 24, 2018, 5:21 p.m.