This is a convenient way to obtain the XML tag name of each of the sub-nodes of a given XMLNode object.

# S3 method for class 'XMLNode'
names(x)

Arguments

x

the XMLNode whose sub-node tag names are being queried.

Value

A character vector returning the tag names of the sub-nodes of the given XMLNode argument.

Author

Duncan Temple Lang

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)).

See also

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"