1\name{ensureNamespace} 2\alias{ensureNamespace} 3\title{Ensure that the node has a definition for particular XML namespaces} 4\description{ 5 This function is a helper function for use in creating XML content. 6 We often want to create a node that will be part of a larger XML tree 7 and use a particular namespace for that node name. Rather than 8 defining the namespace in each new node, we want to ensure that 9 it is define on an ancestor node. This function aids in that task. 10 We call the function with the ancestor node or top-level document 11 and have it check whether the namespace is already defined or have 12 it add it to the node and return. 13 14 This is intended for use with \code{XMLInternalNode} objects 15 which are direclty mutable (rather than changing a copy of the node 16 and having to insert that back into the larger tree.) 17} 18\usage{ 19ensureNamespace(doc, what) 20} 21\arguments{ 22 \item{doc}{an \code{XMLInternalDocument} or \code{XMLInternalNode} on 23 which the namespace is to be defined. If this is a documentm, we use 24 the root node.} 25 \item{what}{a named character vector giving the URIs for the namespace 26 definitions and the names giving the desired prefixes} 27} 28\value{ 29 This is used for the potential side effects of modifying the 30 XML node to add (some of) the namespaces as needed. 31} 32\references{XML namespaces} 33\author{Duncan Temple Lang} 34\seealso{ 35 \code{\link{newXMLNamespace}} 36 \code{\link{newXMLNode}} 37} 38\examples{ 39 doc = newXMLDoc() 40 top = newXMLNode("article", doc = doc) 41 ensureNamespace(top, c(r = "http://www.r-project.org")) 42 b = newXMLNode("r:code", parent = top) 43 print(doc) 44} 45\keyword{IO} 46\concept{XML} 47 48