Rev 8200 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{xmlGetAttr}\alias{xmlGetAttr}\title{Get the value of an attribute in an XML node}\description{This is a convenience function that retrievesthe value of a named attribute in an XML node,taking care of checking for its existence.It also allows the caller to provide a defaultvalue to use as the return value if theattribute is not present.}\usage{xmlGetAttr(node, name, default = NULL, converter = NULL,namespaceDefinition = character(),addNamespace = length(grep(":", name)) > 0)}%- maybe also `usage' for other objects documented here.\arguments{\item{node}{the XML node}\item{name}{the name of the attribute}\item{default}{a value to use as the default return if the attributeis not present in the XML node. }\item{converter}{an optional function which if supplied is invokedwith the attribute value and the value returned.This can be used to convert the string to an arbitraryvalue which is useful if it is, for example, a number.This is only called if the attribute exists within the node.In other words, it is not applied to the \code{default} value.}\item{namespaceDefinition}{a named character vector givingname space prefixes and URIs to use when resolving for thethe attribute with a namespace.The values are used to compare the name space prefix used inthe \code{name} given by the user to the name spacedefinition in the node to ensure they match.This is important as we might ask for an attribute named\code{r:width} assuming that the prefix \code{r} corresponded to theURI \code{http://www.r-project.org}. However, there maybe a name space prefix \code{r} defined on the node that pointsto a different URI and so this would be an erroneous match.}\item{addNamespace}{a logical value that indicates whether we should put thenamespace prefix on the resulting name.This is passed on to \code{\link{xmlAttrs}} and so controls whether the resultingattribute names have the prefix attached.So one specifies \code{TRUE} for this argument if the attribute identifierhas a namespace prefix.}}\details{This just checks that the attribute list isnon-NULL and that there is an element withthe specified name.}\value{If theattribute is present,the return value is a string which is the value of the attribute.Otherwise, the value of \code{default} is returned.}\references{\url{https://www.w3.org/XML/}, \url{http://www.jclark.com/xml/},\url{https://www.omegahat.net} }\author{ Duncan Temple Lang }\seealso{\code{\link{xmlAttrs}}}\examples{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")}\keyword{file}