1\name{xmlToList}
2\alias{xmlToList}
3\title{Convert an XML node/document to a more R-like list}
4\description{
5 This function is an early and simple approach to converting
6an XML node or document into a more typical R list containing
7the data values directly (rather than as XML nodes).
8It is useful for dealing with data that is returned from
9REST requests or other Web queries or generally when parsing
10XML and wanting to  be able to access the content
11as elements in a list indexed by the name of the node.
12For example, if given a node of the form
13\code{
14  <x>
15     <a>text</a>
16     <b foo="1"/>
17     <c bar="me">
18        <d>a phrase</d>
19     </c>
20  </x>
21}
22We would end up with a list with elements named "a", "b" and "c".
23"a" would be the string "text", b would contain the named character
24vector \code{c(foo = "1")} (i.e. the attributes) and "c" would
25contain the list with two elements named "d" and ".attrs".
26The element corresponding to "d" is a
27character vector with the single element "a phrase".
28The ".attrs" element of the list is the character vector of
29attributes from the node \code{<c>...</c>}.
30}
31\usage{
32xmlToList(node, addAttributes = TRUE, simplify = FALSE)
33}
34\arguments{
35  \item{node}{the XML node or document to be converted to an R list.
36   This can be an "internal" or C-level node (i.e. \code{\link{XMLInternalNode-class}})
37   or a regular R-level node (either \code{\link{XMLNode-class}} or \code{XMLHashNode}).}
38  \item{addAttributes}{a logical value which controls whether the attributes of an empty node
39    are added to the }
40  \item{simplify}{a logical value that controls whether we collapse
41   the list to a vector if the elements all have a common compatible
42   type. Basically, this controls whether we use \code{sapply} or \code{lapply}.
43 }
44}
45\value{
46 A list whose elements correspond to the children of the top-level nodes.
47}
48\author{Duncan Temple Lang}
49\seealso{
50 \code{\link{xmlTreeParse}}
51 \code{\link{getNodeSet}} and \code{\link{xpathApply}}
52 \code{\link{xmlRoot}},  \code{\link{xmlChildren}},  \code{\link{xmlApply}}, \code{[[}, etc. for
53 accessing the content of XML nodes.
54}
55\examples{
56tt =
57 '<x>
58     <a>text</a>
59     <b foo="1"/>
60     <c bar="me">
61        <d>a phrase</d>
62     </c>
63  </x>'
64
65  doc = xmlParse(tt)
66  xmlToList(doc)
67
68   # use an R-level node representation
69  doc = xmlTreeParse(tt)
70  xmlToList(doc)
71}
72\keyword{IO}
73\keyword{data}
74
75