Convenience accessors for the children of XMLNode objects.
xmlSubset.RdThese provide a simplified syntax for extracting the children of an XML node.
Usage
# S3 method for class 'XMLNode'
x[..., all = FALSE]
# S3 method for class 'XMLNode'
x[[...]]
# S3 method for class 'XMLDocumentContent'
x[[...]]Arguments
- x
the XML node or the top-level document content in which the children are to be accessed. The
XMLDocumentContentis 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.
- ...
the identifiers for the children to be retrieved, given as integer indices, names, etc. in the usual format for the generic
link{[}andlink{[[}operators- all
logical value. When ... is a character vector, a value of
TRUEforallmeans to retrieve all of the nodes with those names rather than just the first one.FALSEgives the usual result of subsetting a list by name which gives just the first element. This allows us to avoid the idiomnode[ names(node) == "bob" ]which is complicated when node is the result of an inline computation and instead we usenode["bob", all = TRUE].
Value
A list or single element containing the
children of the XML node given by obj
and identified by ....
See also
xmlAttrs
[<-.XMLNode
[[<-.XMLNode
Examples
f = system.file("exampleData", "gnumeric.xml", package = "XML")
top = xmlRoot(xmlTreeParse(f))
# Get the first RowInfo element.
top[["Sheets"]][[1]][["Rows"]][["RowInfo"]]
#> <gmr:RowInfo No="1" Unit="18.000000" MarginA="1.000000" MarginB="1.000000" HardSize="0"/>
# Get a list containing only the first row element
top[["Sheets"]][[1]][["Rows"]]["RowInfo"]
#> $RowInfo
#> <gmr:RowInfo No="1" Unit="18.000000" MarginA="1.000000" MarginB="1.000000" HardSize="0"/>
#>
#> attr(,"class")
#> [1] "XMLNodeList"
top[["Sheets"]][[1]][["Rows"]][1]
#> $RowInfo
#> <gmr:RowInfo No="1" Unit="18.000000" MarginA="1.000000" MarginB="1.000000" HardSize="0"/>
#>
#> attr(,"class")
#> [1] "XMLNodeList"
# Get all of the RowInfo elements by position
top[["Sheets"]][[1]][["Rows"]][1:xmlSize(top[["Sheets"]][[1]][["Rows"]])]
#> $RowInfo
#> <gmr:RowInfo No="1" Unit="18.000000" MarginA="1.000000" MarginB="1.000000" HardSize="0"/>
#>
#> $RowInfo
#> <gmr:RowInfo No="2" Unit="18.000000" MarginA="1.000000" MarginB="1.000000" HardSize="0"/>
#>
#> $RowInfo
#> <gmr:RowInfo No="3" Unit="18.000000" MarginA="1.000000" MarginB="1.000000" HardSize="0"/>
#>
#> $RowInfo
#> <gmr:RowInfo No="4" Unit="18.000000" MarginA="1.000000" MarginB="1.000000" HardSize="0"/>
#>
#> $RowInfo
#> <gmr:RowInfo No="5" Unit="18.000000" MarginA="1.000000" MarginB="1.000000" HardSize="0"/>
#>
#> $RowInfo
#> <gmr:RowInfo No="6" Unit="18.000000" MarginA="1.000000" MarginB="1.000000" HardSize="0"/>
#>
#> $RowInfo
#> <gmr:RowInfo No="7" Unit="18.000000" MarginA="1.000000" MarginB="1.000000" HardSize="0"/>
#>
#> attr(,"class")
#> [1] "XMLNodeList"
# But more succinctly and accurately, get all of the RowInfo elements
top[["Sheets"]][[1]][["Rows"]]["RowInfo", all = TRUE]
#> $RowInfo
#> <gmr:RowInfo No="1" Unit="18.000000" MarginA="1.000000" MarginB="1.000000" HardSize="0"/>
#>
#> $RowInfo
#> <gmr:RowInfo No="2" Unit="18.000000" MarginA="1.000000" MarginB="1.000000" HardSize="0"/>
#>
#> $RowInfo
#> <gmr:RowInfo No="3" Unit="18.000000" MarginA="1.000000" MarginB="1.000000" HardSize="0"/>
#>
#> $RowInfo
#> <gmr:RowInfo No="4" Unit="18.000000" MarginA="1.000000" MarginB="1.000000" HardSize="0"/>
#>
#> $RowInfo
#> <gmr:RowInfo No="5" Unit="18.000000" MarginA="1.000000" MarginB="1.000000" HardSize="0"/>
#>
#> $RowInfo
#> <gmr:RowInfo No="6" Unit="18.000000" MarginA="1.000000" MarginB="1.000000" HardSize="0"/>
#>
#> $RowInfo
#> <gmr:RowInfo No="7" Unit="18.000000" MarginA="1.000000" MarginB="1.000000" HardSize="0"/>
#>
#> attr(,"class")
#> [1] "XMLNodeList"