omegahat / XML

The XML package for R
Other
20 stars 11 forks source link

R: saveXML prefix standalone="yes" outputting as standalone="true" #17

Closed jmallettCSG-zz closed 3 years ago

jmallettCSG-zz commented 3 years ago

I am attempting to create a simple XML file that is sourced from an R dataframe along with preamble/header that includes the following text: standalone="yes"

This would follow: xml version="1.0" encoding="UTF-8"

However, when including this in the prefix argument in the saveXML function as such: prefix = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n'

the preamble reads instead as: <?xml version="1.0" encoding="UTF-8" standalone="true"?>

I've read through much of the documentation, but cannot figure out how to do this, and I do not understand why it is converting the text "yes" to "true". Is this an issue with how the prefix is saved? When I provide the file argument, this occurs, but when this is omitted, the xml output to the console prints standalone="yes" correctly. For reference, here is reproducible code that successfully creates an XML file from an R dataframe, but with the incorrect preamble:

data<- structure(list(page = c("Page One", "Page Two"), base64 = c("Very Long String thats a base64 character", "Very Long String thats a base64 character")), .Names = c("page", "base64"), row.names = 1:2, class = "data.frame") names(data) <- c("title", "page")

library(XML) xml <- xmlTree()

names(xml)

xml$addTag("report", close=FALSE, attrs=c(type="enhanced")) xml$addTag("pages", close=FALSE) for (i in 1:nrow(data)) { xml$addTag("page", close=FALSE) for (j in names(data)) { xml$addTag(j, data[i, j]) } xml$closeTag() } xml$closeTag() xml$closeTag() saveXML(xml,file="test.xml",prefix = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n')

jmallettCSG-zz commented 3 years ago

This was an issue with opening the file using the wrong application - please ignore