ensureNamespace             package:XML             R Documentation

_E_n_s_u_r_e _t_h_a_t _t_h_e _n_o_d_e _h_a_s _a _d_e_f_i_n_i_t_i_o_n _f_o_r _p_a_r_t_i_c_u_l_a_r _X_M_L _n_a_m_e_s_p_a_c_e_s

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

     This function is a helper function for use in creating XML
     content. We often want to create a node that will be part of a
     larger XML tree and use a particular namespace for that node name.
     Rather than defining the namespace in each  new node, we want to
     ensure that it is define on an ancestor node.  This function aids
     in that task. We call the function with  the ancestor node or
     top-level document and have it check whether the namespace is
     already defined or have it add it to the node and return.

     This is intended for use with 'XMLInternalNode' objects which are
     direclty mutable (rather than changing a copy of the node and
     having to insert that back into the larger tree.)

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

     ensureNamespace(doc, what)

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

     doc: an 'XMLInternalDocument' or 'XMLInternalNode' on which the
          namespace is to be defined.  If this is a documentm, we use
          the root node.

    what: a named character vector giving the URIs for the namespace
          definitions and the names giving the desired prefixes

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

     This is used for the potential side effects of modifying the XML
     node to add (some of) the namespaces as needed.

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

     Duncan Temple Lang

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

     XML namespaces

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

     'newXMLNamespace' 'newXMLNode'

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

       doc = newXMLDoc()
       top = newXMLNode("article", doc = doc)
       ensureNamespace(top, c(r = "http://www.r-project.org"))
       b = newXMLNode("r:code", parent = top)
       print(doc)

