Last chance! 50% off unlimited learning
Sale ends in
This turns an XML document (or node or nodeset) into the equivalent R
list. Note that this is as_list()
, not as.list()
:
lapply()
automatically calls as.list()
on its inputs, so
we can't override the default.
as_list(x, ns = character(), ...)
A document, node, or node set.
Optionally, a named vector giving prefix-url pairs, as produced
by xml_ns()
. If provided, all names will be explicitly
qualified with the ns prefix, i.e. if the element bar
is defined
in namespace foo
, it will be called foo:bar
. (And
similarly for attributes). Default namespaces must be given an explicit
name. The ns is ignored when using xml_name<-()
and
xml_set_name()
.
Needed for compatibility with generic. Unused.
as_list
currently only handles the four most common types of
children that an element might have:
Other elements, converted to lists.
Attributes, stored as R attributes. Attributes that have special meanings in R
(class()
, comment()
, dim()
,
dimnames()
, names()
, row.names()
and
tsp()
) are escaped with '.'
Text, stored as a character vector.
as_list(read_xml(" a "))
as_list(read_xml(" "))
as_list(read_xml(""))
as_list(read_xml(""))
Run the code above in your browser using DataLab