アプリでエラーをスローし続ける大量の特殊文字を含む大きな xml ファイルをインポートしようとしています。何かトークン エラーが発生する前に、XML ファイル内の約 76 レコードを処理します。{"クエリの解析中にエラーが発生しました。[トークン行番号 = 1、トークン行オフセット = 725、エラーのトークン = S]"}
私は自分のコードを以下に置きました。
public void ReadXMLIntoDB()
{
OpenFileDialog ofd;
ofd = new OpenFileDialog();
ofd.Filter = "Xml Files|*.xml|AllFiles|*.*";
ofd.ShowDialog();
StreamReader sr = new StreamReader(ofd.FileName);
XmlTextReader xr = new XmlTextReader(sr);
int iNumRows = 0;
while (xr.ReadToFollowing("row") != false)
{
string sFacName, sFacID, sAddress, sCity, sState, sZip, sOwnerID, sOwnerName, sStreetNum, sStreetName, sStreetType, sPostDirectional, sPhone, sProgramCat, sProgramCatDes, sInspectionDate, sInspectionType, sInspectionDes, sSerialNum, sActionCode, sActionDes, sResultCode, sResultDes, sViolationCode, sViolationDes, sInspectionMemo;
xr.ReadToFollowing("value");
sFacName = xr.ReadInnerXml();
xr.ReadToFollowing("value");
sFacID = xr.ReadInnerXml();
xr.ReadToFollowing("value");
sAddress = xr.ReadInnerXml();
xr.ReadToFollowing("value");
sCity = xr.ReadInnerXml();
xr.ReadToFollowing("value");
sState = xr.ReadInnerXml();
xr.ReadToFollowing("value");
sZip = xr.ReadInnerXml();
xr.ReadToFollowing("value");
sOwnerID = xr.ReadInnerXml();
xr.ReadToFollowing("value");
sOwnerName = xr.ReadInnerXml();
xr.ReadToFollowing("value");
sStreetNum = xr.ReadInnerXml();
xr.ReadToFollowing("value");
sStreetName = xr.ReadInnerXml();
xr.ReadToFollowing("value");
sStreetType = xr.ReadInnerXml();
xr.ReadToFollowing("value");
sPostDirectional = xr.ReadInnerXml();
xr.ReadToFollowing("value");
sPhone = xr.ReadInnerXml();
xr.ReadToFollowing("value");
sProgramCat = xr.ReadInnerXml();
xr.ReadToFollowing("value");
sProgramCatDes = xr.ReadInnerXml();
xr.ReadToFollowing("value");
sInspectionDate = xr.ReadInnerXml();
xr.ReadToFollowing("value");
sInspectionType = xr.ReadInnerXml();
xr.ReadToFollowing("value");
sInspectionDes = xr.ReadInnerXml();
xr.ReadToFollowing("value");
sSerialNum = xr.ReadInnerXml();
xr.ReadToFollowing("value");
sActionCode = xr.ReadInnerXml();
xr.ReadToFollowing("value");
sActionDes = xr.ReadInnerXml();
xr.ReadToFollowing("value");
sResultCode = xr.ReadInnerXml();
xr.ReadToFollowing("value");
sResultDes = xr.ReadInnerXml();
xr.ReadToFollowing("value");
sViolationCode = xr.ReadInnerXml();
xr.ReadToFollowing("value");
sViolationDes = xr.ReadInnerXml();
xr.ReadToFollowing("value");
sInspectionMemo = xr.ReadInnerXml();
Regex.Replace(sInspectionMemo, @"[^\w\&#.@-]", "");
SqlCeConnection con;
SqlCeCommand cmd;
string cstr, sql;
cstr = @"Data Source=|DataDirectory|\foodDB.sdf";
sql = String.Format("Insert Into food(FacilityName,FacilityID,SiteAddress,City,State,ZipCode,OwnerID,OwnerName,StreetNumber,StreetName,StreetType,PostDirectional,Phone,ProgramCategory,ProgramCategoryDescription,InspectionDate,InspectionType,InspectionDescription,SerialNumber,ActionCode,ActionDescription,ResultCode,ResultDescription,ViolationCode,ViolationDescription,InspectionMemo) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}','{18}','{19}','{20}','{21}','{22}','{23}','{24}','{25}')", sFacName, sFacID, sAddress, sCity, sState, sZip, sOwnerID, sOwnerName, sStreetNum, sStreetName, sStreetType, sPostDirectional, sPhone, sProgramCat, sProgramCatDes, sInspectionDate, sInspectionType, sInspectionDes, sSerialNum, sActionCode, sActionDes, sResultCode, sResultDes, sViolationCode, sViolationDes, sInspectionMemo);
con = new SqlCeConnection(cstr);
cmd = new SqlCeCommand(sql, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
++iNumRows;
Action ac = delegate()
{
txrows.Text = iNumRows.ToString();
};
Dispatcher.BeginInvoke(ac);
}
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
Thread t = new Thread(ReadXMLIntoDB);
t.Start();
}
私が知る限り、そのレコードでエラーを引き起こす可能性がある唯一の明らかな点は、' が存在するはずの場所に '' があることです。誰か助けてくれませんか?