In a previous question I asked about reading in an XML file into R and carry out basic statistical analysis such as finding the mean and the standard deviation etc. This question is about the reverse of the reading of the original XML file and creating a new XML file that contains the original data and the results from the statistical analysis carried out in R. Is it possible to do this?
Asked
Active
Viewed 343 times
2
-
3See the HTML introduction to the XML package, specifically the section "Creating XML" http://www.omegahat.org/RSXML/shortIntro.html – Greg Jul 21 '10 at 20:04
1 Answers
2
Just use the XML package. E.g.:
library(XML)
# from the package documentation:
b = newXMLNode("bob")
saveXML(b)
f = tempfile()
saveXML(b, f)
doc = xmlInternalTreeParse(f)
saveXML(doc)
con <- xmlOutputDOM()
con$addTag("author", "Duncan Temple Lang")
con$addTag("address", close=FALSE)
con$addTag("office", "2C-259")
con$addTag("street", "Mountain Avenue.")
con$addTag("phone", close=FALSE)
con$addTag("area", "908", attrs=c(state="NJ"))
con$addTag("number", "582-3217")
con$closeTag() # phone
con$closeTag() # address
saveXML(con$value(), file="out.xml")

daroczig
- 28,004
- 7
- 90
- 124