xmlGetAttr                package:XML                R Documentation

_G_e_t _t_h_e _v_a_l_u_e _o_f _a_n _a_t_t_r_i_b_u_t_e _i_n _a_n _X_M_L _n_o_d_e

_D_e_s_c_r_i_p_t_i_o_n:

     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.

_U_s_a_g_e:

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

_A_r_g_u_m_e_n_t_s:

    node: the XML node

    name: the name of the attribute

 default: a value to use as the default return if the attribute is not
          present in the XML node. 

converter: an optional function which if supplied is invoked with the
          attribute value and the value returned. This can be used to
          convert the string to an arbitrary value 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 'default' value.

namespaceDefinition: a named character vector giving name space
          prefixes and URIs to use when resolving for the the attribute
          with a namespace. The values are used to compare the name
          space prefix used in the 'name' given by the user to the name
          space  definition in the node to ensure they match. This is
          important as we might ask for an attribute named 'r:width'
          assuming that the prefix 'r' corresponded to the URI
          'http://www.r-project.org'. However, there may  be a name
          space prefix 'r' defined on the node that points to  a
          different URI and so this would be an erroneous match. 

_D_e_t_a_i_l_s:

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

_V_a_l_u_e:

     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.

_A_u_t_h_o_r(_s):

     Duncan Temple Lang

_R_e_f_e_r_e_n_c_e_s:

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

_S_e_e _A_l_s_o:

     'xmlAttrs'

_E_x_a_m_p_l_e_s:

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

