xml2/ 0000755 0001762 0000144 00000000000 13643540352 011141 5 ustar ligges users xml2/NAMESPACE 0000644 0001762 0000144 00000013747 13643426060 012373 0 ustar ligges users # Generated by roxygen2: do not edit by hand
S3method("[",xml_missing)
S3method("[",xml_nodeset)
S3method("[[",xml_missing)
S3method("xml_attr<-",xml_missing)
S3method("xml_attr<-",xml_node)
S3method("xml_attr<-",xml_nodeset)
S3method("xml_attrs<-",xml_missing)
S3method("xml_attrs<-",xml_node)
S3method("xml_attrs<-",xml_nodeset)
S3method("xml_name<-",xml_missing)
S3method("xml_name<-",xml_node)
S3method("xml_name<-",xml_nodeset)
S3method("xml_text<-",xml_missing)
S3method("xml_text<-",xml_node)
S3method("xml_text<-",xml_nodeset)
S3method(as.character,xml_document)
S3method(as.character,xml_missing)
S3method(as.character,xml_node)
S3method(as.character,xml_nodeset)
S3method(as_list,xml_document)
S3method(as_list,xml_missing)
S3method(as_list,xml_node)
S3method(as_list,xml_nodeset)
S3method(as_xml_document,character)
S3method(as_xml_document,connection)
S3method(as_xml_document,list)
S3method(as_xml_document,raw)
S3method(as_xml_document,response)
S3method(as_xml_document,xml_document)
S3method(as_xml_document,xml_node)
S3method(as_xml_document,xml_nodeset)
S3method(format,xml_node)
S3method(is.na,xml_missing)
S3method(is.na,xml_node)
S3method(is.na,xml_nodeset)
S3method(nodeset_apply,xml_document)
S3method(nodeset_apply,xml_missing)
S3method(nodeset_apply,xml_node)
S3method(nodeset_apply,xml_nodeset)
S3method(print,xml_document)
S3method(print,xml_missing)
S3method(print,xml_namespace)
S3method(print,xml_node)
S3method(print,xml_nodeset)
S3method(read_html,default)
S3method(read_html,response)
S3method(read_xml,character)
S3method(read_xml,connection)
S3method(read_xml,raw)
S3method(read_xml,response)
S3method(tree_structure,xml_missing)
S3method(tree_structure,xml_node)
S3method(tree_structure,xml_nodeset)
S3method(write_html,xml_document)
S3method(write_html,xml_missing)
S3method(write_html,xml_node)
S3method(write_html,xml_nodeset)
S3method(write_xml,xml_document)
S3method(write_xml,xml_missing)
S3method(write_xml,xml_node)
S3method(write_xml,xml_nodeset)
S3method(xml_add_child,xml_document)
S3method(xml_add_child,xml_missing)
S3method(xml_add_child,xml_node)
S3method(xml_add_child,xml_nodeset)
S3method(xml_add_parent,xml_missing)
S3method(xml_add_parent,xml_node)
S3method(xml_add_parent,xml_nodeset)
S3method(xml_add_sibling,xml_missing)
S3method(xml_add_sibling,xml_node)
S3method(xml_add_sibling,xml_nodeset)
S3method(xml_attr,xml_missing)
S3method(xml_attr,xml_node)
S3method(xml_attr,xml_nodeset)
S3method(xml_attrs,xml_missing)
S3method(xml_attrs,xml_node)
S3method(xml_attrs,xml_nodeset)
S3method(xml_double,xml_missing)
S3method(xml_double,xml_node)
S3method(xml_double,xml_nodeset)
S3method(xml_find_all,xml_missing)
S3method(xml_find_all,xml_node)
S3method(xml_find_all,xml_nodeset)
S3method(xml_find_chr,xml_missing)
S3method(xml_find_chr,xml_node)
S3method(xml_find_chr,xml_nodeset)
S3method(xml_find_first,xml_node)
S3method(xml_find_first,xml_nodeset)
S3method(xml_find_lgl,xml_missing)
S3method(xml_find_lgl,xml_node)
S3method(xml_find_lgl,xml_nodeset)
S3method(xml_find_num,xml_missing)
S3method(xml_find_num,xml_node)
S3method(xml_find_num,xml_nodeset)
S3method(xml_integer,xml_missing)
S3method(xml_integer,xml_node)
S3method(xml_integer,xml_nodeset)
S3method(xml_length,xml_missing)
S3method(xml_length,xml_node)
S3method(xml_length,xml_nodeset)
S3method(xml_name,xml_missing)
S3method(xml_name,xml_node)
S3method(xml_name,xml_nodeset)
S3method(xml_ns,xml_document)
S3method(xml_ns,xml_missing)
S3method(xml_ns,xml_node)
S3method(xml_ns,xml_nodeset)
S3method(xml_parent,xml_missing)
S3method(xml_parent,xml_node)
S3method(xml_parent,xml_nodeset)
S3method(xml_path,xml_missing)
S3method(xml_path,xml_node)
S3method(xml_path,xml_nodeset)
S3method(xml_remove,xml_missing)
S3method(xml_remove,xml_node)
S3method(xml_remove,xml_nodeset)
S3method(xml_replace,xml_missing)
S3method(xml_replace,xml_node)
S3method(xml_replace,xml_nodeset)
S3method(xml_serialize,xml_document)
S3method(xml_serialize,xml_node)
S3method(xml_serialize,xml_nodeset)
S3method(xml_set_attr,xml_missing)
S3method(xml_set_attr,xml_node)
S3method(xml_set_attr,xml_nodeset)
S3method(xml_set_attrs,xml_missing)
S3method(xml_set_attrs,xml_node)
S3method(xml_set_attrs,xml_nodeset)
S3method(xml_set_name,xml_missing)
S3method(xml_set_name,xml_node)
S3method(xml_set_name,xml_nodeset)
S3method(xml_text,xml_missing)
S3method(xml_text,xml_node)
S3method(xml_text,xml_nodeset)
S3method(xml_type,xml_missing)
S3method(xml_type,xml_node)
S3method(xml_type,xml_nodeset)
S3method(xml_url,xml_missing)
S3method(xml_url,xml_node)
S3method(xml_url,xml_nodeset)
S3method(xml_validate,xml_document)
export("xml_attr<-")
export("xml_attrs<-")
export("xml_name<-")
export("xml_text<-")
export(as_list)
export(as_xml_document)
export(download_html)
export(download_xml)
export(html_structure)
export(read_html)
export(read_xml)
export(url_absolute)
export(url_escape)
export(url_parse)
export(url_relative)
export(url_unescape)
export(write_html)
export(write_xml)
export(xml2_example)
export(xml_add_child)
export(xml_add_parent)
export(xml_add_sibling)
export(xml_attr)
export(xml_attrs)
export(xml_cdata)
export(xml_child)
export(xml_children)
export(xml_comment)
export(xml_contents)
export(xml_double)
export(xml_dtd)
export(xml_find_all)
export(xml_find_chr)
export(xml_find_first)
export(xml_find_lgl)
export(xml_find_num)
export(xml_find_one)
export(xml_has_attr)
export(xml_integer)
export(xml_length)
export(xml_missing)
export(xml_name)
export(xml_new_document)
export(xml_new_root)
export(xml_ns)
export(xml_ns_rename)
export(xml_ns_strip)
export(xml_parent)
export(xml_parents)
export(xml_path)
export(xml_remove)
export(xml_replace)
export(xml_root)
export(xml_serialize)
export(xml_set_attr)
export(xml_set_attrs)
export(xml_set_name)
export(xml_set_namespace)
export(xml_set_text)
export(xml_siblings)
export(xml_structure)
export(xml_text)
export(xml_type)
export(xml_unserialize)
export(xml_url)
export(xml_validate)
exportClasses(xml_document)
exportClasses(xml_missing)
exportClasses(xml_node)
exportClasses(xml_nodeset)
importFrom(methods,setOldClass)
useDynLib(xml2, .registration = TRUE)
xml2/tools/ 0000755 0001762 0000144 00000000000 13516067254 012305 5 ustar ligges users xml2/tools/winlibs.R 0000644 0001762 0000144 00000000666 13516067254 014107 0 ustar ligges users # Build against static libraries from rwinlib
VERSION <- commandArgs(TRUE)
if(!file.exists(sprintf("../windows/libxml2-%s/include/libxml2/libxml/parser.h", VERSION))){
if(getRversion() < "3.3.0") setInternet2()
download.file(sprintf("https://github.com/rwinlib/libxml2/archive/v%s.zip", VERSION), "lib.zip", quiet = TRUE)
dir.create("../windows", showWarnings = FALSE)
unzip("lib.zip", exdir = "../windows")
unlink("lib.zip")
}
xml2/README.md 0000644 0001762 0000144 00000004156 13637645657 012447 0 ustar ligges users # xml2
[](https://github.com/r-lib/xml2/actions)
[](https://travis-ci.org/r-lib/xml2)
[](https://codecov.io/github/r-lib/xml2?branch=master)
The xml2 package is a binding to [libxml2](http://xmlsoft.org), making it easy to work with HTML and XML from R. The API is somewhat inspired by [jQuery](http://jquery.com).
## Installation
You can install xml2 from CRAN,
```R
install.packages("xml2")
```
or you can install the development version from github, using `devtools`:
```R
# install.packages("devtools")
devtools::install_github("r-lib/xml2")
```
## Usage
```R
library("xml2")
x <- read_xml(" text ")
x
xml_name(x)
xml_children(x)
xml_text(x)
xml_find_all(x, ".//baz")
h <- read_html("
Hi !")
h
xml_name(h)
xml_text(h)
```
There are three key classes:
* `xml_node`: a single node in a document.
* `xml_doc`: the complete document. Acting on a document is usually the same
as acting on the root node of the document.
* `xml_nodeset`: a __set__ of nodes within the document. Operations on
`xml_nodeset`s are vectorised, apply the operation over each node in the set.
## Compared to the XML package
xml2 has similar goals to the XML package. The main differences are:
* xml2 takes care of memory management for you. It will automatically
free the memory used by an XML document as soon as the last reference
to it goes away.
* xml2 has a very simple class hierarchy so don't need to think about exactly
what type of object you have, xml2 will just do the right thing.
* More convenient handling of namespaces in Xpath expressions - see `xml_ns()`
and `xml_ns_strip()` to get started.
## Code of Conduct
Please note that the xml2 project is released with a [Contributor Code of Conduct](https://xml2.r-lib.org/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.
xml2/man/ 0000755 0001762 0000144 00000000000 13637645657 011735 5 ustar ligges users xml2/man/xml_validate.Rd 0000644 0001762 0000144 00000001230 13516067254 014654 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/xml_schema.R
\name{xml_validate}
\alias{xml_validate}
\title{Validate XML schema}
\usage{
xml_validate(x, schema)
}
\arguments{
\item{x}{A document, node, or node set.}
\item{schema}{an XML document containing the schema}
}
\value{
TRUE or FALSE
}
\description{
Validate an XML document against an XML 1.0 schema.
}
\examples{
# Example from https://msdn.microsoft.com/en-us/library/ms256129(v=vs.110).aspx
doc <- read_xml(system.file("extdata/order-doc.xml", package = "xml2"))
schema <- read_xml(system.file("extdata/order-schema.xml", package = "xml2"))
xml_validate(doc, schema)
}
xml2/man/xml_type.Rd 0000644 0001762 0000144 00000000605 13516067254 014051 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/xml_type.R
\name{xml_type}
\alias{xml_type}
\title{Determine the type of a node.}
\usage{
xml_type(x)
}
\arguments{
\item{x}{A document, node, or node set.}
}
\description{
Determine the type of a node.
}
\examples{
x <- read_xml(" a ")
xml_type(x)
xml_type(xml_contents(x))
}
xml2/man/xml_missing.Rd 0000644 0001762 0000144 00000000402 13516067254 014534 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/classes.R
\name{xml_missing}
\alias{xml_missing}
\title{Construct an missing xml object}
\usage{
xml_missing()
}
\description{
Construct an missing xml object
}
\keyword{internal}
xml2/man/xml_attr.Rd 0000644 0001762 0000144 00000006124 13631731660 014041 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/xml_attr.R
\name{xml_attr}
\alias{xml_attr}
\alias{xml_has_attr}
\alias{xml_attrs}
\alias{xml_attr<-}
\alias{xml_set_attr}
\alias{xml_attrs<-}
\alias{xml_set_attrs}
\title{Retrieve an attribute.}
\usage{
xml_attr(x, attr, ns = character(), default = NA_character_)
xml_has_attr(x, attr, ns = character())
xml_attrs(x, ns = character())
xml_attr(x, attr, ns = character()) <- value
xml_set_attr(x, attr, value, ns = character())
xml_attrs(x, ns = character()) <- value
xml_set_attrs(x, value, ns = character())
}
\arguments{
\item{x}{A document, node, or node set.}
\item{attr}{Name of attribute to extract.}
\item{ns}{Optionally, a named vector giving prefix-url pairs, as produced
by \code{\link[=xml_ns]{xml_ns()}}. If provided, all names will be explicitly
qualified with the ns prefix, i.e. if the element \code{bar} is defined
in namespace \code{foo}, it will be called \code{foo:bar}. (And
similarly for attributes). Default namespaces must be given an explicit
name. The ns is ignored when using \code{\link[=xml_name<-]{xml_name<-()}} and
\code{\link[=xml_set_name]{xml_set_name()}}.}
\item{default}{Default value to use when attribute is not present.}
\item{value}{character vector of new value.}
}
\value{
\code{xml_attr()} returns a character vector. \code{NA} is used
to represent of attributes that aren't defined.
\code{xml_has_attr()} returns a logical vector.
\code{xml_attrs()} returns a named character vector if \code{x} x is single
node, or a list of character vectors if given a nodeset
}
\description{
\code{xml_attrs()} retrieves all attributes values as a named character
vector, \verb{xml_attrs() <-} or \code{xml_set_attrs()} sets all attribute
values. \code{xml_attr()} retrieves the value of single attribute and
\verb{xml_attr() <-} or \code{xml_set_attr()} modifies its value. If the
attribute doesn't exist, it will return \code{default}, which defaults to
\code{NA}. \code{xml_has_attr()} tests if an attribute is present.
}
\examples{
x <- read_xml("")
xml_attr(x, "id")
xml_attr(x, "apple")
xml_attrs(x)
kids <- xml_children(x)
kids
xml_attr(kids, "id")
xml_has_attr(kids, "id")
xml_attrs(kids)
# Missing attributes give missing values
xml_attr(xml_children(x), "d")
xml_has_attr(xml_children(x), "d")
# If the document has a namespace, use the ns argument and
# qualified attribute names
x <- read_xml('
')
doc <- xml_children(x)[[1]]
ns <- xml_ns(x)
xml_attrs(doc)
xml_attrs(doc, ns)
# If you don't supply a ns spec, you get the first matching attribute
xml_attr(doc, "id")
xml_attr(doc, "b:id", ns)
xml_attr(doc, "id", ns)
# Can set a single attribute with `xml_attr() <-` or `xml_set_attr()`
xml_attr(doc, "id") <- "one"
xml_set_attr(doc, "id", "two")
# Or set multiple attributes with `xml_attrs()` or `xml_set_attrs()`
xml_attrs(doc) <- c("b:id" = "one", "f:id" = "two", "id" = "three")
xml_set_attrs(doc, c("b:id" = "one", "f:id" = "two", "id" = "three"))
}
xml2/man/xml_children.Rd 0000644 0001762 0000144 00000004507 13631515545 014664 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/xml_children.R
\name{xml_children}
\alias{xml_children}
\alias{xml_child}
\alias{xml_contents}
\alias{xml_parents}
\alias{xml_siblings}
\alias{xml_parent}
\alias{xml_length}
\alias{xml_root}
\title{Navigate around the family tree.}
\usage{
xml_children(x)
xml_child(x, search = 1, ns = xml_ns(x))
xml_contents(x)
xml_parents(x)
xml_siblings(x)
xml_parent(x)
xml_length(x, only_elements = TRUE)
xml_root(x)
}
\arguments{
\item{x}{A document, node, or node set.}
\item{search}{For \code{xml_child}, either the child number to return (by
position), or the name of the child node to return. If there are multiple
child nodes with the same name, the first will be returned}
\item{ns}{Optionally, a named vector giving prefix-url pairs, as produced
by \code{\link[=xml_ns]{xml_ns()}}. If provided, all names will be explicitly
qualified with the ns prefix, i.e. if the element \code{bar} is defined
in namespace \code{foo}, it will be called \code{foo:bar}. (And
similarly for attributes). Default namespaces must be given an explicit
name. The ns is ignored when using \code{\link[=xml_name<-]{xml_name<-()}} and
\code{\link[=xml_set_name]{xml_set_name()}}.}
\item{only_elements}{For \code{xml_length}, should it count all children,
or just children that are elements (the default)?}
}
\value{
A node or nodeset (possibly empty). Results are always de-duplicated.
}
\description{
\code{xml_children} returns only elements, \code{xml_contents} returns
all nodes. \code{xml_length} returns the number of children.
\code{xml_parent} returns the parent node, \code{xml_parents}
returns all parents up to the root. \code{xml_siblings} returns all nodes
at the same level. \code{xml_child} makes it easy to specify a specific
child to return.
}
\examples{
x <- read_xml(" ")
xml_children(x)
xml_children(xml_children(x))
xml_siblings(xml_children(x)[[1]])
# Note the each unique node only appears once in the output
xml_parent(xml_children(x))
# Mixed content
x <- read_xml(" a c e f")
# Childen gets the elements, contents gets all node types
xml_children(x)
xml_contents(x)
xml_length(x)
xml_length(x, only_elements = FALSE)
# xml_child makes it easier to select specific children
xml_child(x)
xml_child(x, 2)
xml_child(x, "baz")
}
xml2/man/xml_new_document.Rd 0000644 0001762 0000144 00000002576 13631731660 015565 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/xml_modify.R
\name{xml_new_document}
\alias{xml_new_document}
\alias{xml_new_root}
\title{Create a new document, possibly with a root node}
\usage{
xml_new_document(version = "1.0", encoding = "UTF-8")
xml_new_root(
.value,
...,
.copy = inherits(.value, "xml_node"),
.version = "1.0",
.encoding = "UTF-8"
)
}
\arguments{
\item{version}{The version number of the document.}
\item{encoding}{The character encoding to use in the document. The default
encoding is \sQuote{UTF-8}. Available encodings are specified at
\url{http://xmlsoft.org/html/libxml-encoding.html#xmlCharEncoding}.}
\item{.value}{node to insert.}
\item{...}{If named attributes or namespaces to set on the node, if unnamed
text to assign to the node.}
\item{.copy}{whether to copy the \code{.value} before replacing. If this is \code{FALSE}
then the node will be moved from it's current location.}
\item{.version}{The version number of the document, passed to \code{xml_new_document(version)}.}
\item{.encoding}{The encoding of the document, passed to \code{xml_new_document(encoding)}.}
}
\value{
A \code{xml_document} object.
}
\description{
\code{xml_new_document} creates only a new document without a root node. In
most cases you should instead use \code{xml_new_root}, which creates a new
document and assigns the root node in one step.
}
xml2/man/url_escape.Rd 0000644 0001762 0000144 00000001010 13637645657 014336 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/xml_url.R
\name{url_escape}
\alias{url_escape}
\alias{url_unescape}
\title{Escape and unescape urls.}
\usage{
url_escape(x, reserved = "")
url_unescape(x)
}
\arguments{
\item{x}{A character vector of urls.}
\item{reserved}{A string containing additional characters to avoid escaping.}
}
\description{
Escape and unescape urls.
}
\examples{
url_escape("a b c")
url_escape("a b c", "")
url_unescape("a\%20b\%2fc")
url_unescape("\%C2\%B5")
}
xml2/man/xml_set_namespace.Rd 0000644 0001762 0000144 00000000727 13516067254 015704 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/xml_modify.R
\name{xml_set_namespace}
\alias{xml_set_namespace}
\title{Set the node's namespace}
\usage{
xml_set_namespace(.x, prefix = "", uri = "")
}
\arguments{
\item{.x}{a node}
\item{prefix}{The namespace prefix to use}
\item{uri}{The namespace URI to use}
}
\value{
the node (invisibly)
}
\description{
The namespace to be set must be already defined in one of the node's
ancestors.
}
xml2/man/xml_find_all.Rd 0000644 0001762 0000144 00000007142 13631515545 014642 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/xml_find.R
\name{xml_find_all}
\alias{xml_find_all}
\alias{xml_find_first}
\alias{xml_find_num}
\alias{xml_find_chr}
\alias{xml_find_lgl}
\alias{xml_find_one}
\title{Find nodes that match an xpath expression.}
\usage{
xml_find_all(x, xpath, ns = xml_ns(x))
xml_find_first(x, xpath, ns = xml_ns(x))
xml_find_num(x, xpath, ns = xml_ns(x))
xml_find_chr(x, xpath, ns = xml_ns(x))
xml_find_lgl(x, xpath, ns = xml_ns(x))
}
\arguments{
\item{x}{A document, node, or node set.}
\item{xpath}{A string containing a xpath (1.0) expression.}
\item{ns}{Optionally, a named vector giving prefix-url pairs, as produced
by \code{\link[=xml_ns]{xml_ns()}}. If provided, all names will be explicitly
qualified with the ns prefix, i.e. if the element \code{bar} is defined
in namespace \code{foo}, it will be called \code{foo:bar}. (And
similarly for attributes). Default namespaces must be given an explicit
name. The ns is ignored when using \code{\link[=xml_name<-]{xml_name<-()}} and
\code{\link[=xml_set_name]{xml_set_name()}}.}
}
\value{
\code{xml_find_all} always returns a nodeset: if there are no matches
the nodeset will be empty. The result will always be unique; repeated
nodes are automatically de-duplicated.
\code{xml_find_first} returns a node if applied to a node, and a nodeset
if applied to a nodeset. The output is \emph{always} the same size as
the input. If there are no matches, \code{xml_find_first} will return a
missing node; if there are multiple matches, it will return the first
only.
\code{xml_find_num}, \code{xml_find_chr}, \code{xml_find_lgl} return
numeric, character and logical results respectively.
}
\description{
Xpath is like regular expressions for trees - it's worth learning if
you're trying to extract nodes from arbitrary locations in a document.
Use \code{xml_find_all} to find all matches - if there's no match you'll
get an empty result. Use \code{xml_find_first} to find a specific match -
if there's no match you'll get an \code{xml_missing} node.
}
\section{Deprecated functions}{
\code{xml_find_one()} has been deprecated. Instead use
\code{xml_find_first()}.
}
\examples{
x <- read_xml("")
xml_find_all(x, ".//baz")
xml_path(xml_find_all(x, ".//baz"))
# Note the difference between .// and //
# // finds anywhere in the document (ignoring the current node)
# .// finds anywhere beneath the current node
(bar <- xml_find_all(x, ".//bar"))
xml_find_all(bar, ".//baz")
xml_find_all(bar, "//baz")
# Find all vs find one -----------------------------------------------------
x <- read_xml("
Some text.
Some other text.
No bold here!
")
para <- xml_find_all(x, ".//p")
# If you apply xml_find_all to a nodeset, it finds all matches,
# de-duplicates them, and returns as a single list. This means you
# never know how many results you'll get
xml_find_all(para, ".//b")
# xml_find_first only returns the first match per input node. If there are 0
# matches it will return a missing node
xml_find_first(para, ".//b")
xml_text(xml_find_first(para, ".//b"))
# Namespaces ---------------------------------------------------------------
# If the document uses namespaces, you'll need use xml_ns to form
# a unique mapping between full namespace url and a short prefix
x <- read_xml('
')
xml_find_all(x, ".//f:doc")
xml_find_all(x, ".//f:doc", xml_ns(x))
}
\seealso{
\code{\link[=xml_ns_strip]{xml_ns_strip()}} to remove the default namespaces
}
xml2/man/read_xml.Rd 0000644 0001762 0000144 00000007425 13631731660 014007 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/xml_parse.R
\name{read_xml}
\alias{read_xml}
\alias{read_html}
\alias{read_xml.character}
\alias{read_xml.raw}
\alias{read_xml.connection}
\title{Read HTML or XML.}
\usage{
read_xml(x, encoding = "", ..., as_html = FALSE, options = "NOBLANKS")
read_html(x, encoding = "", ..., options = c("RECOVER", "NOERROR", "NOBLANKS"))
\method{read_xml}{character}(x, encoding = "", ..., as_html = FALSE, options = "NOBLANKS")
\method{read_xml}{raw}(
x,
encoding = "",
base_url = "",
...,
as_html = FALSE,
options = "NOBLANKS"
)
\method{read_xml}{connection}(
x,
encoding = "",
n = 64 * 1024,
verbose = FALSE,
...,
base_url = "",
as_html = FALSE,
options = "NOBLANKS"
)
}
\arguments{
\item{x}{A string, a connection, or a raw vector.
A string can be either a path, a url or literal xml. Urls will
be converted into connections either using \code{base::url} or, if
installed, \code{curl::curl}. Local paths ending in \code{.gz},
\code{.bz2}, \code{.xz}, \code{.zip} will be automatically uncompressed.
If a connection, the complete connection is read into a raw vector before
being parsed.}
\item{encoding}{Specify a default encoding for the document. Unless
otherwise specified XML documents are assumed to be in UTF-8 or
UTF-16. If the document is not UTF-8/16, and lacks an explicit
encoding directive, this allows you to supply a default.}
\item{...}{Additional arguments passed on to methods.}
\item{as_html}{Optionally parse an xml file as if it's html.}
\item{options}{Set parsing options for the libxml2 parser. Zero or more of
\Sexpr[results=rd]{xml2:::describe_options(xml2:::xml_parse_options())}}
\item{base_url}{When loading from a connection, raw vector or literal
html/xml, this allows you to specify a base url for the document. Base
urls are used to turn relative urls into absolute urls.}
\item{n}{If \code{file} is a connection, the number of bytes to read per
iteration. Defaults to 64kb.}
\item{verbose}{When reading from a slow connection, this prints some
output on every iteration so you know its working.}
}
\value{
An XML document. HTML is normalised to valid XML - this may not
be exactly the same transformation performed by the browser, but it's
a reasonable approximation.
}
\description{
Read HTML or XML.
}
\section{Setting the "user agent" header}{
When performing web scraping tasks it is both good practice --- and often required ---
to set the \href{https://en.wikipedia.org/wiki/User_agent}{user agent} request header
to a specific value. Sometimes this value is assigned to emulate a browser in order
to have content render in a certain way (e.g. \verb{Mozilla/5.0 (Windows NT 5.1; rv:52.0) Gecko/20100101 Firefox/52.0} to emulate more recent Windows browsers). Most often,
this value should be set to provide the web resource owner information on who you are
and the intent of your actions like this Google scraping bot user agent identifier:
\verb{Googlebot/2.1 (+http://www.google.com/bot.html)}.
You can set the HTTP user agent for URL-based requests using \code{\link[httr:set_config]{httr::set_config()}} and \code{\link[httr:user_agent]{httr::user_agent()}}:
\code{httr::set_config(httr::user_agent("me@example.com; +https://example.com/info.html"))}
\code{\link[httr:set_config]{httr::set_config()}} changes the configuration globally,
\code{\link[httr:with_config]{httr::with_config()}} can be used to change configuration temporarily.
}
\examples{
# Literal xml/html is useful for small examples
read_xml("")
read_html("Hi")
read_html("Hi")
# From a local path
read_html(system.file("extdata", "r-project.html", package = "xml2"))
\dontrun{
# From a url
cd <- read_xml(xml2_example("cd_catalog.xml"))
me <- read_html("http://had.co.nz")
}
}
xml2/man/xml_text.Rd 0000644 0001762 0000144 00000002306 13516067254 014054 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/xml_text.R
\name{xml_text}
\alias{xml_text}
\alias{xml_text<-}
\alias{xml_set_text}
\alias{xml_double}
\alias{xml_integer}
\title{Extract or modify the text}
\usage{
xml_text(x, trim = FALSE)
xml_text(x) <- value
xml_set_text(x, value)
xml_double(x)
xml_integer(x)
}
\arguments{
\item{x}{A document, node, or node set.}
\item{trim}{If \code{TRUE} will trim leading and trailing spaces.}
\item{value}{character vector with replacement text.}
}
\value{
A character vector, the same length as x.
}
\description{
\code{xml_text} returns a character vector, \code{xml_double} returns a
numeric vector, \code{xml_integer} returns an integer vector.
}
\examples{
x <- read_xml("This is some text. This is bold!
")
xml_text(x)
xml_text(xml_children(x))
x <- read_xml("This is some text. This is some nested text.")
xml_text(x)
xml_text(xml_find_all(x, "//x"))
x <- read_xml(" Some text
")
xml_text(x, trim = TRUE)
# xml_double() and xml_integer() are useful for extracting numeric
attributes
x <- read_xml("")
xml_integer(xml_find_all(x, "//@x"))
}
xml2/man/oldclass.Rd 0000644 0001762 0000144 00000001260 13631515545 014011 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/S4.R
\name{xml_document-class}
\alias{xml_document-class}
\alias{xml_missing-class}
\alias{xml_node-class}
\alias{xml_nodeset-class}
\title{Register S4 classes}
\description{
Classes are exported so they can be re-used within S4 classes, see \code{\link[methods:setOldClass]{methods::setOldClass()}}.
\code{xml_document}: a complete document.
\code{xml_missing}: a missing object, e.g. for an empty result set.
\code{xml_node}: a single node in a document.
\code{xml_nodeset}: a \emph{set} of nodes within a document.
}
\concept{xml_document}
\concept{xml_missing}
\concept{xml_node}
\concept{xml_nodeset}
xml2/man/url_absolute.Rd 0000644 0001762 0000144 00000001544 13637645657 014730 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/xml_url.R
\name{url_absolute}
\alias{url_absolute}
\alias{url_relative}
\title{Convert between relative and absolute urls.}
\usage{
url_absolute(x, base)
url_relative(x, base)
}
\arguments{
\item{x}{A character vector of urls relative to that base}
\item{base}{A string giving a base url.}
}
\value{
A character vector of urls
}
\description{
Convert between relative and absolute urls.
}
\examples{
url_absolute(c(".", "..", "/", "/x"), "http://hadley.nz/a/b/c/d")
url_relative("http://hadley.nz/a/c", "http://hadley.nz")
url_relative("http://hadley.nz/a/c", "http://hadley.nz/")
url_relative("http://hadley.nz/a/c", "http://hadley.nz/a/b")
url_relative("http://hadley.nz/a/c", "http://hadley.nz/a/b/")
}
\seealso{
\code{\link{xml_url}} to retrieve the URL associated with a document
}
xml2/man/xml_comment.Rd 0000644 0001762 0000144 00000000625 13516067254 014534 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/classes.R
\name{xml_comment}
\alias{xml_comment}
\title{Construct a comment node}
\usage{
xml_comment(content)
}
\arguments{
\item{content}{The comment content}
}
\description{
Construct a comment node
}
\examples{
x <- xml_new_document()
r <- xml_add_child(x, "root")
xml_add_child(r, xml_comment("Hello!"))
as.character(x)
}
xml2/man/xml_url.Rd 0000644 0001762 0000144 00000001025 13631515545 013666 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/xml_url.R
\name{xml_url}
\alias{xml_url}
\title{The URL of an XML document}
\usage{
xml_url(x)
}
\arguments{
\item{x}{A node or document.}
}
\value{
A character vector of length 1. Returns \code{NA} if the name is
not set.
}
\description{
This is useful for interpreting relative urls with \code{\link[=url_relative]{url_relative()}}.
}
\examples{
catalog <- read_xml(xml2_example("cd_catalog.xml"))
xml_url(catalog)
x <- read_xml("")
xml_url(x)
}
xml2/man/url_parse.Rd 0000644 0001762 0000144 00000001130 13637645657 014213 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/xml_url.R
\name{url_parse}
\alias{url_parse}
\title{Parse a url into its component pieces.}
\usage{
url_parse(x)
}
\arguments{
\item{x}{A character vector of urls.}
}
\value{
A dataframe with one row for each element of \code{x} and
columns: scheme, server, port, user, path, query, fragment.
}
\description{
Parse a url into its component pieces.
}
\examples{
url_parse("http://had.co.nz/")
url_parse("http://had.co.nz:1234/")
url_parse("http://had.co.nz:1234/?a=1&b=2")
url_parse("http://had.co.nz:1234/?a=1&b=2#def")
}
xml2/man/download_xml.Rd 0000644 0001762 0000144 00000003335 13631731660 014677 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/xml_parse.R
\name{download_xml}
\alias{download_xml}
\alias{download_html}
\title{Download a HTML or XML file}
\usage{
download_xml(
url,
file = basename(url),
quiet = TRUE,
mode = "wb",
handle = curl::new_handle()
)
download_html(
url,
file = basename(url),
quiet = TRUE,
mode = "wb",
handle = curl::new_handle()
)
}
\arguments{
\item{url}{A character string naming the URL of a resource to be downloaded.}
\item{file}{A character string with the name where the downloaded file is
saved.}
\item{quiet}{If \code{TRUE}, suppress status messages (if any), and the
progress bar.}
\item{mode}{A character string specifying the mode with which to write the file.
Useful values are \code{"w"}, \code{"wb"} (binary), \code{"a"} (append)
and \code{"ab"}.}
\item{handle}{a curl handle object}
}
\value{
Path of downloaded file (invisibly).
}
\description{
Libcurl implementation of \code{C_download} (the "internal" download method)
with added support for https, ftps, gzip, etc. Default behavior is identical
to \code{\link[=download.file]{download.file()}}, but request can be fully configured by passing
a custom \code{\link[curl:handle]{curl::handle()}}.
}
\details{
The main difference between \code{curl_download} and \code{curl_fetch_disk}
is that \code{curl_download} checks the http status code before starting the
download, and raises an error when status is non-successful. The behavior of
\code{curl_fetch_disk} on the other hand is to proceed as normal and write
the error page to disk in case of a non success response.
}
\examples{
\dontrun{
download_html("http://tidyverse.org/index.html")
}
}
\seealso{
\link[curl:curl_download]{curl_download}
}
xml2/man/xml_dtd.Rd 0000644 0001762 0000144 00000001661 13516067254 013646 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/classes.R
\name{xml_dtd}
\alias{xml_dtd}
\title{Construct a document type definition}
\usage{
xml_dtd(name = "", external_id = "", system_id = "")
}
\arguments{
\item{name}{The name of the declaration}
\item{external_id}{The external ID of the declaration}
\item{system_id}{The system ID of the declaration}
}
\description{
This is used to create simple document type definitions. If you need to
create a more complicated definition with internal subsets it is recommended
to parse a string directly with \code{read_xml()}.
}
\examples{
r <- xml_new_root(
xml_dtd("html",
"-//W3C//DTD XHTML 1.0 Transitional//EN",
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"))
# Use read_xml directly for more complicated DTD
d <- read_xml(
'
]>
This is a valid document &foo; !')
}
xml2/man/as_xml_document.Rd 0000644 0001762 0000144 00000001676 13516067254 015402 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/as_xml_document.R
\name{as_xml_document}
\alias{as_xml_document}
\title{Coerce a R list to xml nodes.}
\usage{
as_xml_document(x, ...)
}
\arguments{
\item{x}{A document, node, or node set.}
\item{...}{Needed for compatibility with generic. Unused.}
}
\description{
This turns an R list into the equivalent XML document. Not all R lists will
produce valid XML, in particular there can only be one root node and all
child nodes need to be named (or empty) lists. R attributes become XML
attributes and R names become XML node names.
}
\examples{
as_xml_document(list(x = list()))
# Nesting multiple nodes
as_xml_document(list(foo = list(bar = list(baz = list()))))
# attributes are stored as R attributes
as_xml_document(list(foo = structure(list(), id = "a")))
as_xml_document(list(foo = list(
bar = structure(list(), id = "a"),
bar = structure(list(), id = "b"))))
}
xml2/man/xml_ns_strip.Rd 0000644 0001762 0000144 00000001300 13516067254 014722 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/xml_modify.R
\name{xml_ns_strip}
\alias{xml_ns_strip}
\title{Strip the default namespaces from a document}
\usage{
xml_ns_strip(x)
}
\arguments{
\item{x}{A document, node, or node set.}
}
\description{
Strip the default namespaces from a document
}
\examples{
x <- read_xml(
"
")
# Need to specify the default namespaces to find the baz nodes
xml_find_all(x, "//d1:baz")
xml_find_all(x, "//d2:baz")
# After stripping the default namespaces you can find both baz nodes directly
xml_ns_strip(x)
xml_find_all(x, "//baz")
}
xml2/man/as_list.Rd 0000644 0001762 0000144 00000003455 13631515545 013653 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/as_list.R
\name{as_list}
\alias{as_list}
\title{Coerce xml nodes to a list.}
\usage{
as_list(x, ns = character(), ...)
}
\arguments{
\item{x}{A document, node, or node set.}
\item{ns}{Optionally, a named vector giving prefix-url pairs, as produced
by \code{\link[=xml_ns]{xml_ns()}}. If provided, all names will be explicitly
qualified with the ns prefix, i.e. if the element \code{bar} is defined
in namespace \code{foo}, it will be called \code{foo:bar}. (And
similarly for attributes). Default namespaces must be given an explicit
name. The ns is ignored when using \code{\link[=xml_name<-]{xml_name<-()}} and
\code{\link[=xml_set_name]{xml_set_name()}}.}
\item{...}{Needed for compatibility with generic. Unused.}
}
\description{
This turns an XML document (or node or nodeset) into the equivalent R
list. Note that this is \code{as_list()}, not \code{as.list()}:
\code{lapply()} automatically calls \code{as.list()} on its inputs, so
we can't override the default.
}
\details{
\code{as_list} currently only handles the four most common types of
children that an element might have:
\itemize{
\item Other elements, converted to lists.
\item Attributes, stored as R attributes. Attributes that have special meanings in R
(\code{\link[=class]{class()}}, \code{\link[=comment]{comment()}}, \code{\link[=dim]{dim()}},
\code{\link[=dimnames]{dimnames()}}, \code{\link[=names]{names()}}, \code{\link[=row.names]{row.names()}} and
\code{\link[=tsp]{tsp()}}) are escaped with '.'
\item Text, stored as a character vector.
}
}
\examples{
as_list(read_xml(" a ]]>"))
as_list(read_xml(" "))
as_list(read_xml(""))
as_list(read_xml(""))
}
xml2/man/xml_replace.Rd 0000644 0001762 0000144 00000003361 13631731660 014502 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/xml_modify.R
\name{xml_replace}
\alias{xml_replace}
\alias{xml_add_sibling}
\alias{xml_add_child}
\alias{xml_add_parent}
\alias{xml_remove}
\title{Modify a tree by inserting, replacing or removing nodes}
\usage{
xml_replace(.x, .value, ..., .copy = TRUE)
xml_add_sibling(.x, .value, ..., .where = c("after", "before"), .copy = TRUE)
xml_add_child(.x, .value, ..., .where = length(xml_children(.x)), .copy = TRUE)
xml_add_parent(.x, .value, ...)
xml_remove(.x, free = FALSE)
}
\arguments{
\item{.x}{a document, node or nodeset.}
\item{.value}{node to insert.}
\item{...}{If named attributes or namespaces to set on the node, if unnamed
text to assign to the node.}
\item{.copy}{whether to copy the \code{.value} before replacing. If this is \code{FALSE}
then the node will be moved from it's current location.}
\item{.where}{to add the new node, for \code{xml_add_child} the position
after which to add, use \code{0} for the first child. For
\code{xml_add_sibling} either \sQuote{"before"} or \sQuote{"after"}
indicating if the new node should be before or after \code{.x}.}
\item{free}{When removing the node also free the memory used for that node.
Note if you use this option you cannot use any existing objects pointing to
the node or its children, it is likely to crash R or return garbage.}
}
\description{
\code{xml_add_sibling()} and \code{xml_add_child()} are used to insert a node
as a sibling or a child. \code{xml_add_parent()} adds a new parent in
between the input node and the current parent. \code{xml_replace()}
replaces an existing node with a new node. \code{xml_remove()} removes a
node from the tree.
}
\details{
Care needs to be taken when using \code{xml_remove()},
}
xml2/man/xml_path.Rd 0000644 0001762 0000144 00000000751 13516067254 014026 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/xml_path.R
\name{xml_path}
\alias{xml_path}
\title{Retrieve the xpath to a node}
\usage{
xml_path(x)
}
\arguments{
\item{x}{A document, node, or node set.}
}
\value{
A character vector.
}
\description{
This is useful when you want to figure out where nodes matching an
xpath expression live in a document.
}
\examples{
x <- read_xml("")
xml_path(xml_find_all(x, ".//baz"))
}
xml2/man/write_xml.Rd 0000644 0001762 0000144 00000002730 13631731660 014220 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/xml_write.R
\name{write_xml}
\alias{write_xml}
\alias{write_xml.xml_document}
\alias{write_html}
\alias{write_html.xml_document}
\title{Write XML or HTML to disk.}
\usage{
write_xml(x, file, ...)
\method{write_xml}{xml_document}(x, file, ..., options = "format", encoding = "UTF-8")
write_html(x, file, ...)
\method{write_html}{xml_document}(x, file, ..., options = "format", encoding = "UTF-8")
}
\arguments{
\item{x}{A document or node to write to disk. It's not possible to
save nodesets containing more than one node.}
\item{file}{Path to file or connection to write to.}
\item{...}{additional arguments passed to methods.}
\item{options}{default: \sQuote{format}. Zero or more of
\Sexpr[results=rd]{xml2:::describe_options(xml2:::xml_save_options())}}
\item{encoding}{The character encoding to use in the document. The default
encoding is \sQuote{UTF-8}. Available encodings are specified at
\url{http://xmlsoft.org/html/libxml-encoding.html#xmlCharEncoding}.}
}
\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
\code{option = "as_xml"} or \code{option = "as_html"} respectively.
}
\examples{
h <- read_html("Hi!
")
tmp <- tempfile(fileext = ".xml")
write_xml(h, tmp, options = "format")
readLines(tmp)
# write formatted HTML output
write_html(h, tmp, options = "format")
readLines(tmp)
}
xml2/man/xml_name.Rd 0000644 0001762 0000144 00000002255 13631515545 014012 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/xml_name.R
\name{xml_name}
\alias{xml_name}
\alias{xml_name<-}
\alias{xml_set_name}
\title{The (tag) name of an xml element.}
\usage{
xml_name(x, ns = character())
xml_name(x, ns = character()) <- value
xml_set_name(x, value, ns = character())
}
\arguments{
\item{x}{A document, node, or node set.}
\item{ns}{Optionally, a named vector giving prefix-url pairs, as produced
by \code{\link[=xml_ns]{xml_ns()}}. If provided, all names will be explicitly
qualified with the ns prefix, i.e. if the element \code{bar} is defined
in namespace \code{foo}, it will be called \code{foo:bar}. (And
similarly for attributes). Default namespaces must be given an explicit
name. The ns is ignored when using \code{\link[=xml_name<-]{xml_name<-()}} and
\code{\link[=xml_set_name]{xml_set_name()}}.}
\item{value}{a character vector with replacement name.}
}
\value{
A character vector.
}
\description{
The (tag) name of an xml element.
Modify the (tag) name of an element
}
\examples{
x <- read_xml("123")
xml_name(x)
y <- read_xml("1abc")
z <- xml_children(y)
xml_name(xml_children(y))
}
xml2/man/xml_cdata.Rd 0000644 0001762 0000144 00000000614 13631731660 014141 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/classes.R
\name{xml_cdata}
\alias{xml_cdata}
\title{Construct a cdata node}
\usage{
xml_cdata(content)
}
\arguments{
\item{content}{The CDATA content, does not include \verb{"))
as.character(x)
}
xml2/man/xml_serialize.Rd 0000644 0001762 0000144 00000001726 13631731660 015061 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/xml_serialize.R
\name{xml_serialize}
\alias{xml_serialize}
\alias{xml_unserialize}
\title{Serializing XML objects to connections.}
\usage{
xml_serialize(object, connection, ...)
xml_unserialize(connection, ...)
}
\arguments{
\item{object}{\R object to serialize.}
\item{connection}{an open \link[base]{connection} or (for \code{serialize})
\code{NULL} or (for \code{unserialize}) a raw vector
(see \sQuote{Details}).}
\item{...}{Additional arguments passed to \code{\link[=read_xml]{read_xml()}}.}
}
\value{
For \code{serialize}, \code{NULL} unless \code{connection = NULL}, when
the result is returned in a raw vector.
For \code{unserialize} an \R object.
}
\description{
Serializing XML objects to connections.
}
\examples{
library(xml2)
x <- read_xml("
123
456
")
b <- xml_find_all(x, "//b")
out <- xml_serialize(b, NULL)
xml_unserialize(out)
}
xml2/man/xml2_example.Rd 0000644 0001762 0000144 00000000663 13516067254 014611 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utils.R
\name{xml2_example}
\alias{xml2_example}
\title{Get path to a xml2 example}
\usage{
xml2_example(path = NULL)
}
\arguments{
\item{path}{Name of file. If \code{NULL}, the example files will be listed.}
}
\description{
xml2 comes bundled with a number of sample files in its \sQuote{inst/extdata}
directory. This function makes them easy to access.
}
xml2/man/xml_structure.Rd 0000644 0001762 0000144 00000002504 13631731660 015125 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/xml_structure.R
\name{xml_structure}
\alias{xml_structure}
\alias{html_structure}
\title{Show the structure of an html/xml document.}
\usage{
xml_structure(x, indent = 2, file = "")
html_structure(x, indent = 2, file = "")
}
\arguments{
\item{x}{HTML/XML document (or part there of)}
\item{indent}{Number of spaces to ident}
\item{file}{A \link[base]{connection}, or a character string naming the file
to print to. If \code{""} (the default), \code{cat} prints to the
standard output connection, the console unless redirected by
\code{\link[base]{sink}}.
If it is \code{"|cmd"}, the output is piped to the command given
by \file{cmd}, by opening a pipe connection.
}
}
\description{
Show the structure of an html/xml document without displaying any of
the values. This is useful if you want to get a high level view of the
way a document is organised. Compared to \code{xml_structure},
\code{html_structure} prints the id and class attributes.
}
\examples{
xml_structure(read_xml(""))
rproj <- read_html(system.file("extdata","r-project.html", package = "xml2"))
xml_structure(rproj)
xml_structure(xml_find_all(rproj, ".//p"))
h <- read_html("")
html_structure(h)
}
xml2/man/xml_ns.Rd 0000644 0001762 0000144 00000002621 13631515545 013507 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/xml_namespaces.R
\name{xml_ns}
\alias{xml_ns}
\alias{xml_ns_rename}
\title{XML namespaces.}
\usage{
xml_ns(x)
xml_ns_rename(old, ...)
}
\arguments{
\item{x}{A document, node, or node set.}
\item{old, ...}{An existing xml_namespace object followed by name-value
(old prefix-new prefix) pairs to replace.}
}
\value{
A character vector with class \code{xml_namespace} so the
default display is a little nicer.
}
\description{
\code{xml_ns} extracts all namespaces from a document, matching each
unique namespace url with the prefix it was first associated with. Default
namespaces are named \code{d1}, \code{d2} etc. Use \code{xml_ns_rename}
to change the prefixes. Once you have a namespace object, you can pass it to
other functions to work with fully qualified names instead of local names.
}
\examples{
x <- read_xml('
')
xml_ns(x)
# When there are default namespaces, it's a good idea to rename
# them to give informative names:
ns <- xml_ns_rename(xml_ns(x), d1 = "foo", d2 = "bar")
ns
# Now we can pass ns to other xml function to use fully qualified names
baz <- xml_children(xml_children(x))
xml_name(baz)
xml_name(baz, ns)
xml_find_all(x, "//baz")
xml_find_all(x, "//foo:baz", ns)
str(as_list(x))
str(as_list(x, ns))
}
xml2/DESCRIPTION 0000644 0001762 0000144 00000003430 13643540352 012647 0 ustar ligges users Package: xml2
Title: Parse XML
Version: 1.3.1
Authors@R:
c(person(given = "Hadley",
family = "Wickham",
role = "aut",
email = "hadley@rstudio.com"),
person(given = "Jim",
family = "Hester",
role = c("aut", "cre"),
email = "jim.hester@rstudio.com"),
person(given = "Jeroen",
family = "Ooms",
role = "aut"),
person(given = "RStudio",
role = "cph"),
person(given = "R Foundation",
role = "ctb",
comment = "Copy of R-project homepage cached as example"))
Description: Work with XML files using a simple, consistent
interface. Built on top of the 'libxml2' C library.
License: GPL (>= 2)
URL: https://xml2.r-lib.org/, https://github.com/r-lib/xml2
BugReports: https://github.com/r-lib/xml2/issues
Depends: R (>= 3.1.0)
Imports: methods
Suggests: covr, curl, httr, knitr, magrittr, mockery, rmarkdown,
testthat (>= 2.1.0)
VignetteBuilder: knitr
Encoding: UTF-8
RoxygenNote: 7.1.0
SystemRequirements: libxml2: libxml2-dev (deb), libxml2-devel (rpm)
Collate: 'S4.R' 'as_list.R' 'xml_parse.R' 'as_xml_document.R'
'classes.R' 'init.R' 'paths.R' 'utils.R' 'xml_attr.R'
'xml_children.R' 'xml_find.R' 'xml_modify.R' 'xml_name.R'
'xml_namespaces.R' 'xml_path.R' 'xml_schema.R'
'xml_serialize.R' 'xml_structure.R' 'xml_text.R' 'xml_type.R'
'xml_url.R' 'xml_write.R' 'zzz.R'
NeedsCompilation: yes
Packaged: 2020-04-08 19:57:50 UTC; jhester
Author: Hadley Wickham [aut],
Jim Hester [aut, cre],
Jeroen Ooms [aut],
RStudio [cph],
R Foundation [ctb] (Copy of R-project homepage cached as example)
Maintainer: Jim Hester
Repository: CRAN
Date/Publication: 2020-04-09 06:30:02 UTC
xml2/build/ 0000755 0001762 0000144 00000000000 13643426274 012246 5 ustar ligges users xml2/build/vignette.rds 0000644 0001762 0000144 00000000316 13643426274 014605 0 ustar ligges users b```b`fcd`b2 1#'X&/藟]%9h
Pm :I,Q,LHYsSь`wI-HK î?"5lP5,n90{C2K 7(1
棸(\^P4 @btr$$
r xml2/build/xml2.pdf 0000644 0001762 0000144 00000433617 13643426272 013637 0 ustar ligges users %PDF-1.5
%
128 0 obj
<<
/Length 963
/Filter /FlateDecode
>>
stream
xڝV[o6~ϯ$ I^`.-6tC8]n 6jCQV,ǡ=";9$vJ;o/3߫;(w '1|*O{`7Yɼ
Ϸ?xo!aH$$H ϝQL.͗bG҈F̊>J`
z$qةjpJNn&Yݎ+!Lcd]&$oc?F$%X}Wl~a2S Q?:KۊI+Wd_ӊIKޔfuW2yH.k I)D98bސ!wJ%>|UۍƎi|m>/2Ejx;F2d*F!G'\V_A 90Îqц!aZ#[ P+ʵ-BB`Ⱦ?S%pCy['\Tpؾ
Z(}yk.eB,^ǚB
IphsLGxB_7E4S3k;јM,TߑgE\ ƢBދM=7:+Nn;L<#s.L֣9kAAjţ/*c
S9X0a7(Jj@rnЃVF^noVZzFMd(Ј`;Bxvo[؝