fileName <- system.file("data/test.xml", pkg="XML")
# parse the document and return it in its standard format.
xmlTreeParse(fileName)
# parse the document, discarding comments.
xmlTreeParse(fileName, handlers=list("comment"=function(x, parent){NULL}))
invisible(xmlTreeParse(fileName,
handlers=list(entity=function(x) {
cat("In entity",x$name, x$value,"")}
)
)
)
# Parse some XML text.
# Read the text from the file
xmlText <- paste(scan(fileName, what="",sep=""),"", collapse="")
xmlTreeParse(xmlText, asText=T)
# Read a MathML document and convert each node
# so that the primary class is
# <name of tag>MathML
# so that we can use method dispatching when processing
# it rather than conditional statements on the tag name.
# See plotMathML() in examples/.
fileName <- system.file("data/mathml.xml",pkg="XML")
m <- xmlTreeParse(fileName,
handlers=list(startElement=function(node){
cname <- paste(xmlName(node),"MathML",sep="",collapse="")
class(node) <- c(cname, class(node));
node
}))
# Parse an XML document directly from a URL.
# Requires Internet access.
xmlTreeParse("http://www.omegahat.org/Scripts/Data/mtcars.xml", asText=T)
Run the code above in your browser using DataLab