Get the names of an XML nodes children.
names.XMLNode.RdThis is a convenient way to obtain the XML tag name
of each of the sub-nodes of a given
XMLNode object.
Usage
# S3 method for class 'XMLNode'
names(x)Note
This overrides the regular names method
which would display the names of the internal
fields of an XMLNode object.
Since these are intended to be invisible and
queried via the accessor methods (xmlName,
xmlAttrs, etc.), this should not
be a problem. If you really need the names
of the fields, use names(unclass(x)).
Examples
doc <- xmlTreeParse(system.file("exampleData", "mtcars.xml", package="XML"))
names(xmlRoot(doc))
#> variables record record record record record
#> "variables" "record" "record" "record" "record" "record"
#> record record record record record record
#> "record" "record" "record" "record" "record" "record"
#> record record record record record record
#> "record" "record" "record" "record" "record" "record"
#> record record record record record record
#> "record" "record" "record" "record" "record" "record"
#> record record record record record record
#> "record" "record" "record" "record" "record" "record"
#> record record record
#> "record" "record" "record"
r <- xmlRoot(doc)
r[names(r) == "variables"]
#> $variables
#> <variables count="11">
#> <variable unit="Miles/gallon">mpg</variable>
#> <variable>cyl</variable>
#> <variable>disp</variable>
#> <variable>hp</variable>
#> <variable>drat</variable>
#> <variable>wt</variable>
#> <variable>qsec</variable>
#> <variable>vs</variable>
#> <variable type="FactorVariable" levels="automatic,manual">am</variable>
#> <variable>gear</variable>
#> <variable>carb</variable>
#> </variables>
#>
#> attr(,"class")
#> [1] "XMLNodeList"