Anthony Keane
Anthony Keane

Reputation: 821

How to put the results from R into an XML file

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?

Upvotes: 2

Views: 356

Answers (1)

daroczig
daroczig

Reputation: 28632

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")

Upvotes: 2

Related Questions