[英]Using XML in a SQL query
I am trying to query an ACCESS database using R v3.0.3 and am running into repeated SQL syntax errors. 我正在尝试使用R v3.0.3查询ACCESS数据库,并且遇到了重复的SQL语法错误。 My code is as follows.
我的代码如下。
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)
The XML is contained within an XML structure (only pasting the relevant part here) In this example there are six values within the "code code=" block XML包含在XML结构中(仅在此处粘贴相关部分)。在此示例中,“ code code =“块中有六个值
<code code="ECAT">
<editdetail attribution="BIP Coding Group" action="confirmed" date="1996-08-20"/>
</code>
Can anyone help with this? 有人能帮忙吗?
In your SQL statement change the concatenated variable: 在您的SQL语句中,更改串联变量:
xattrs$[i]Code
To 至
xattrs[i]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.