
Last chance! 50% off unlimited learning
Sale ends in
Another approach to finding the origin of the XInclude for a given
node is to search for an attribute xml:base. This only works if the
document being XInclude'd is in a different directory than the base document.
If this is the case, we can use an XPath query to find the node
containing the attribute via "./ancestor::*[@xml:base]"
.
findXInclude(x, asNode = FALSE, recursive = FALSE)
NULL
if there was no node of class XMLXIncludeStartNode
found.
Otherwise, if asNode
is TRUE
, that XMLXIncludeStartNode
node is returned, or alternatively its attribute character vector.xmlParse
and the xinclude
parameter.f = system.file("exampleData", "functionTemplate.xml", package = "XML")
cat(readLines(f), "")
doc = xmlParse(f)
# Get all the para nodes
# We just want to look at the 2nd and 3rd which are repeats of the
# first one.
a = getNodeSet(doc, "//author")
findXInclude(a[[1]])
i = findXInclude(a[[1]], TRUE)
top = getSibling(i)
# Determine the top-level included nodes
tmp = getSibling(i)
nodes = list()
while(!inherits(tmp, "XMLXIncludeEndNode")) {
nodes = c(nodes, tmp)
tmp = getSibling(tmp)
}
Run the code above in your browser using DataLab