Learn R Programming

XML (version 1.7-2)

[.XMLNode: Convenience accessors for the children of XMLNode objects.

Description

These provide a simplified syntax for extracting the children of an XML node.

Usage

obj[[i]]
"[.XMLNode"(obj, ..., all = FALSE)
"[[.XMLNode"(obj, ...)
"[[.XMLDocumentContent"(obj, ...)

Arguments

obj
the XML node or the top-level document content in which the children are to be accessed. The XMLDocumentContent is the container for the top-level node that also contains information such as the URI/filename and XML version. This accessor
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.
...
the identifiers for the children to be retrieved, given as integer indices, names, etc. in the usual format for the generic link{[} and link{[[} operators
all
logical value. When ...is a character vector, a value of TRUE for all means to retrieve all of the nodes with those names rather than just the first one. FALSE gives the usual result of subsetting a list

Value

  • A list or single element containing the children of the XML node given by obj and identified by ....

References

http://www.w3.org/XML, http://www.omegahat.org/RSXML

See Also

xmlAttrs [<-.XMLNode [[<-.XMLNode

Examples

Run this code
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]

Run the code above in your browser using DataLab