Learn R Programming

XML (version 1.2-0)

xmlGetAttr: Get the value of an attribute in an XML node

Description

This is a convenience function that retrieves the value of a named attribute in an XML node, taking care of checking for its existence. It also allows the caller to provide a default value to use as the return value if the attribute is not present.

Usage

xmlGetAttr(node, name, default = NULL, converter = NULL)

Arguments

Value

  • If the attribute is present, the return value is a string which is the value of the attribute. Otherwise, the value of default is returned.

Details

This just checks that the attribute list is non-NULL and that there is an element with the specified name.

References

http://www.w3.org/XML, http://www.jclark.com/xml, http://www.omegahat.org

See Also

xmlAttrs

Examples

Run this code
node <- xmlNode("foo", attrs=c(a="1", b="my name"))

 xmlGetAttr(node, "a")
 xmlGetAttr(node, "doesn't exist", "My own default value")

 xmlGetAttr(node, "b", "Just in case")

Run the code above in your browser using DataLab