myTests/docNode.R

top = newXMLNode("top")
nodes = lapply(c("A", "B", "C"), newXMLNode, parent = top)
subnodes = lapply(c(1, 2),
                  function(i)
                    lapply(c("x", "y", "z"), newXMLNode, i, parent = nodes[[i]]))


assert = function(cond) {
            e = substitute(cond)
            if(!is.logical(cond) || !cond) 
               stop("Assertion failed ", deparse(e), "\n", paste(cond, collapse = "\n"))
            TRUE
          }


test =
function(node, hasDoc = FALSE) {  
 cat(saveXML(node))
 assert(xmlSize(node) == 3)
 assert( is.null(as(node, "XMLInternalDocument")) == !hasDoc)
 assert(all.equal( sapply(xmlChildren(node), as, "XMLInternalDocument"), list(A = NULL, B = NULL, C = NULL)))
 assert(all.equal(xmlApply(top, function(x) xmlApply(x, as, "XMLInternalDocument")),
                  list(A = list(x = NULL, y = NULL, z = NULL), B = list(x = NULL, y = NULL, z = NULL), C = structure(list(), names = character(0)))))
}



doc = newXMLDoc(addFinalizer = FALSE)

test(top)
.Call("RS_XML_setRootNode", doc, top)
test(top, TRUE)

.Call("RS_XML_unsetDoc", top, unlink = FALSE)
test(top)

print(as(top, "XMLInternalDocument"))

.Call("RS_XML_freeDoc", doc);
print(as(top, "XMLInternalDocument"))
omegahat/XML documentation built on Jan. 17, 2024, 6:47 p.m.