在SQL查询中使用XML

在SQL查询中使用XML,xml,r,ms-access,Xml,R,Ms Access,我试图使用Rv3.0.3查询ACCESS数据库,但遇到了多次SQL语法错误。我的代码如下 library(RODBC) library(XML) # Access directory containing the corpus scripts and load all corpus documents dale1 <- "C:/Cerberus_Software_Prototype/TR_Corpus/2286newsML.xml") doc1 <- x

我试图使用Rv3.0.3查询ACCESS数据库,但遇到了多次SQL语法错误。我的代码如下

library(RODBC) 
library(XML)

# Access directory containing the corpus scripts and load all corpus documents    
dale1   <- "C:/Cerberus_Software_Prototype/TR_Corpus/2286newsML.xml")    
doc1    <- xmlInternalTreeParse(dale1)    
xattrs  <- xpathApply(doc1, "//code[@code]", xmlGetAttr, "code")     
xmldf   <- xmlToDataFrame(nodes = getNodeSet(doc1, "//code/code"))      
xattrs1 <- data.frame(xattrs)

# Connect to Accessdb
channel <- odbcConnectAccess("C:/Cerberus_Software_Prototype/R/Economics_data/Cerberus1.mdb")

for (i in 1:6) {
   #  MODIFY SELECT OR ACTION QUERY TO MEET NEEDS, EVEN ADD PARAMS  
   querydf <- sqlQuery(channel, paste0("select All_codes.Description from All_codes 
                                        where All_codes.Code ='", xattrs$[i]Code, "'"))        
 }

close(channel) 
库(RODBC)
库(XML)
#访问包含语料库脚本的目录并加载所有语料库文档

dale1在SQL语句中更改连接的变量:

xattrs$[i]Code


你需要告诉人们语法错误是什么,不仅仅是因为你得到了很多错误。我刚刚关闭了R(32位版本),并试图再次运行脚本。它生成以下错误。查询querydf[i]中的错误到目前为止,它似乎可以工作,有人知道是否有方法计算每个节点中要在for循环中使用的xml数据元素的数量吗?当然,使用
length(xattrs)
。如果解决方案有效,请接受。
xattrs$[i]Code
xattrs[i]