# NOT RUN {
long = runif(10000, -122, -80)
lat = runif(10000, 25, 48)
txt = sprintf("<Placemark><Point><coordinates>%.3f,%.3f,0</coordinates></Point></Placemark>",
long, lat)
f = newXMLNode("Folder")
parseXMLAndAdd(txt, f)
xmlSize(f)
# }
# NOT RUN {
# this version is much slower as i) we don't vectorize the
# creation of the XML nodes, and ii) the parsing of the XML
# as a string is very fast as it is done in C.
f = newXMLNode("Folder")
mapply(function(a, b) {
newXMLNode("Placemark",
newXMLNode("Point",
newXMLNode("coordinates",
paste(a, b, "0", collapse = ","))),
parent = f)
},
long, lat)
xmlSize(f)
o = c("<x>dog</x>", "<omg:x>cat</omg:x>")
node = parseXMLAndAdd(o, nsDefs = c("http://cran.r-project.org",
omg = "http://www.omegahat.net"))
xmlNamespace(node[[1]])
xmlNamespace(node[[2]])
tt = newXMLNode("myTop")
node = parseXMLAndAdd(o, tt, nsDefs = c("http://cran.r-project.org",
omg = "http://www.omegahat.net"))
tt
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab