I have a script to get an XML file from an SQL database. Here is how I do it:
library(RODBC) library(XML) myconn <- odbcConnect("mydsn") query.text <- "SELECT xmlfield FROM db WHERE id = 12345" doc <- sqlQuery(myconn, query.text, stringsAsFactors=FALSE) doc <- iconv(doc[1,1], from="latin1", to="UTF-8") doc <- xmlInternalTreeParse(doc, encoding="UTF-8")
However, parsing did not work for a particular database row, although it did work when I copied the contents of this field to a separate file and parsed it. Two days later, a โtrial errorโ I identified the main problem. It seems that requesting small XML files in this way does not cause any problems, but when I request larger files, the line breaks after 65534 characters. Therefore, the end of the XML file is missing and the file cannot be parsed.
I thought this might be a general limitation of ODBC connections on my computer. However, another program that also uses ODBC to retrieve the same XML field from the same database does this without any problems. Therefore, I assume this is a problem of R
Any ideas how to fix this?
sql r odbc
AnjaM
source share