File: xmlSubset.Rd

package info (click to toggle)
r-cran-xml 3.99-0.19-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,688 kB
  • sloc: ansic: 6,659; xml: 2,890; asm: 486; sh: 12; makefile: 2
file content (77 lines) | stat: -rw-r--r-- 2,581 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
\name{[.XMLNode}
\alias{[.XMLNode}
\alias{[[.XMLNode}
\alias{[[.XMLInternalElementNode}
\alias{[[.XMLDocumentContent}
\title{Convenience accessors for the children of XMLNode objects.}
\description{
 These provide a simplified syntax for extracting the children
of an XML node.
}
\usage{
\method{[}{XMLNode}(x, ..., all = FALSE)
\method{[[}{XMLNode}(x, ...)
\method{[[}{XMLDocumentContent}(x, ...)
}
\arguments{
  \item{x}{the XML node or the top-level document content in which the children are to be accessed.
  The \code{XMLDocumentContent} is the container for the top-level node that also contains information
  such as the URI/filename and XML version. This accessor method is merely a convenience to get 
  access to children of the top-level node.}
% \item{i}{index of the child of interest or the name of an XML element
%   of interest. In this latter case, only the first matching element is
%   returned, if any.}
  \item{\dots}{the identifiers for the children to be retrieved,
given as integer indices, names, etc. in the usual format for the
generic \code{link{[}} and \code{link{[[}} operators}
  \item{all}{logical value.  When \dots is a character vector, a value
    of \code{TRUE} for \code{all} means to retrieve all of the
    nodes with those names rather than just the first one.
    \code{FALSE} gives the usual result of subsetting a list by name
    which gives just the first element.
    This allows us to avoid the  idiom
       \code{node[ names(node) == "bob" ]}
       which is complicated when node is the result of an inline
       computation
       and instead we use
       \code{node["bob", all = TRUE]}.
  }
}
\value{
 A list or single element containing the
children of the XML node given by \code{obj}
and identified by \dots.
}
\references{\url{https://www.w3.org/XML/}, \url{https://www.omegahat.net/RSXML/}}
\author{Duncan Temple Lang}


\seealso{
 \code{\link{xmlAttrs}}
 \code{\link{[<-.XMLNode}}
 \code{\link{[[<-.XMLNode}}
}

\examples{

 f = system.file("exampleData", "gnumeric.xml", package = "XML")

 top = xmlRoot(xmlTreeParse(f))

  # Get the first RowInfo element.
 top[["Sheets"]][[1]][["Rows"]][["RowInfo"]]

  # Get a list containing only the first row element
 top[["Sheets"]][[1]][["Rows"]]["RowInfo"]
 top[["Sheets"]][[1]][["Rows"]][1]

  # Get all of the RowInfo elements by position
 top[["Sheets"]][[1]][["Rows"]][1:xmlSize(top[["Sheets"]][[1]][["Rows"]])]

  # But more succinctly and accurately, get all of the RowInfo elements
 top[["Sheets"]][[1]][["Rows"]]["RowInfo", all = TRUE]

}
\keyword{IO}
\keyword{file}