
This function allows one to search an XML tree from a particular node and find the namespace definition for a given namespace prefix or URL. This namespace definition can then be used to set it on a node to make it the effective namespace for that node.
xmlSearchNs(node, ns, asPrefix = TRUE, doc = as(node, "XMLInternalDocument"))
an XMLInternaElementNode
a character string (vector of length 1).
If asPrefix
is TRUE
, this is the namespace
alias/prefix.
If asPrefix
is FALSE
, this is the URL of the namespace definition
a logical value. See ns
.
the XML document in which the node(s) are located
An object of class XMLNamespaceRef.
libxml2
# NOT RUN {
txt = '<top xmlns:r="http://www.r-project.org"><section><bottom/></section></top>'
doc = xmlParse(txt)
bottom = xmlRoot(doc)[[1]][[1]]
xmlSearchNs(bottom, "r")
# }
Run the code above in your browser using DataLab