https://github.com/cran/XML
Raw File
Tip revision: 0d08c2de1337762727f21c61d03c4406b0b5ee0c authored by Duncan Temple Lang on 14 November 2006, 00:00:00 UTC
version 1.2-0
Tip revision: 0d08c2d
assignChild.R
"[<-.XMLNode" <-
function(x, i, value)
{
  x$children[i] <- value
  if(!is.character(i)) {
       names(x$children)[i] =
               if(inherits(value, "XMLNode"))
                 xmlName(value)
               else
                 sapply(value, xmlName)
  }
 x
}


"[[<-.XMLNode" <-
function(x, i, value)
{
  x$children[[i]] <- value
  if(!is.character(i)) {
       names(x$children)[i] =
               if(inherits(value, "XMLNode"))
                 xmlName(value)
               else
                 sapply(value, xmlName)
  }  
 x
}


append.xmlNode <-
function(to, ...)
{
 UseMethod("append")
}

append.XMLNode <-
function(to, ...)
{
 args <- list(...)
 if(!inherits(args[[1]], "XMLNode") && is.list(args[[1]]))
   args <- args[[1]]
    
 idx <- seq(length(to$children) + 1, length=length(args))

 args = addNames(args)
 
 if(is.null(to$children))
   to$children <- args
 else  {
   to$children[idx] <- args
   names(to$children)[idx] <- names(args)
 }

 to
}

if(FALSE) {
xmlAddChild <-
function(node, child) {
  node$children <- append(node$children, list(child))
  names(node$children) <- sapply(node$children,xmlName)
  node
}
}
back to top