Skip to content
Prev 157567 / 398506 Next

example - export a data frame to an XML file

Hi

Is this what you are after ... ?


data <-
read.csv(textConnection('"date","UYG.Open","UYG.High","UYG.Low","UYG.Close","UYG.Volume","UYG.Adjusted"
"2007-02-01",71.32,71.34,71.32,71.34,200,69.23
"2007-02-02",72.2,72.2,72.2,72.2,200,70.06
"2007-02-05",71.76,71.76,71.76,71.76,5100,69.63
"2007-02-06",72.85,72.85,72.85,72.85,3800,70.69
"2007-02-07",72.85,72.85,72.85,72.85,0,70.69'),
                  as.is=TRUE)

library(XML)

xml <- xmlTree()
xml$addTag("document", close=FALSE)
for (i in 1:nrow(data)) {
    xml$addTag("row", close=FALSE)
    for (j in names(data)) {
        xml$addTag(j, data[i, j])
    }
    xml$closeTag()
}
xml$closeTag()

# view the result
cat(saveXML(xml))


Paul
zubin wrote: