T.Wunder at stud.uni-heidelberg.de
2010-Feb-12 08:57 UTC
[R] Convert data frame to XML-Tree
Hello, I'd like to convert R data frames into xml-trees. I wrote (and copied) this little program to do this: convertToXML <- function(df,name) { xml <- xmlTree("Test") xml$addNode(name, close=FALSE) for (i in 1:nrow(df)) { xml$addNode("value", close=FALSE) for (j in names(df)) { xml$addNode(j, df[i, j]) } xml$closeTag() } xml$closeTag() return(xml) } Well, now I get a warning message like "In xmlRoot.XMLInternalDocument(currentNodes[[1]]) : empty XML document" if I use this function. How could this be fixed? Thank you for your help! Tom
T.Wunder wrote:> > > convertToXML <- function(df,name) > { > xml <- xmlTree("Test") > xml$addNode(name, close=FALSE) > for (i in 1:nrow(df)) { > xml$addNode("value", close=FALSE) > for (j in names(df)) { > xml$addNode(j, df[i, j]) > } > xml$closeTag() > } > xml$closeTag() > return(xml) > } > > Well, now I get a warning message like > "In xmlRoot.XMLInternalDocument(currentNodes[[1]]) : empty XML document" > > if I use this function. How could this be fixed? > >By telling use how you "used" that function. Dieter -- View this message in context: http://n4.nabble.com/Convert-data-frame-to-XML-Tree-tp1478281p1478311.html Sent from the R help mailing list archive at Nabble.com.