开发者

How to put the results from R into an XML file

In a 开发者_如何学JAVAprevious 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?


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜