I have a problem with saving XML file from R.
Firstly I write my code here:
doc = newXMLDoc()
document = newXMLNode("Document", doc = doc)
set = newXMLNode("Settings", parent = document)
elements = newXMLNode("Elements", parent = set)
newXMLNode("Canvas", parent = elements, attrs = c(Id = "1"))
newXMLNode("Canvas", parent = elements, attrs = c(Id = "2"))
objcol = newXMLNode("ObjectCollection", parent = document)
timeSeries1 = newXMLNode("Timeseries", parent = objcol)
timeSeries2 = newXMLNode("Timeseries", parent = objcol)
saveXML(doc, file="test.dtv", indent = T,
prefix = '<?xml version="1.0" encoding="utf-8" standalone="no"?>\n')
So, if I save doc without prefix, all is good, but i haven't prefix in my ouput file. When I add prefix attribute to function saveXML, output is really bad. It has only one '\n' after prefix(because I write it in prefix string), but all document is on one line. I haven't ideas how to fix it. Thank you for your attention.
So, I'am also quite surprised why this is not working, but found a "workaround" to it. Hope this is helpfull.
cat(saveXML(doc,
indent = TRUE,
prefix = "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n"),
file="test.dtv")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With