Now I am trying to make some service where I can read the xml file and parse it into sql server, I am already read and see many tutorial how to parse xml into sql server use c# but still I can't take the data.
<?xml version="1.0" encoding="utf-8" ?>
<Source 1 - Subject 17>
SubjectType: Faces
FaceConfidence: 100
<appeared at 02/08/2018 5:28:43 PM>
FrameIndex: 1033
Rectangle: at (210;169), width=63, height=84
</appeared at 02/08/2018 5:28:43 PM>
<track at 02/08/2018 5:28:44 PM>
FrameIndex: 1050
Rectangle: at (210;134), width=70, height=94
<Details available on frame 1050>
FrameIndex: 1050
Status: Ok
Eyes at: (260; 169) and (229; 169)
Rectangle: at (210;134), width=70, height=94
</Details available on frame 1050>
</track at 02/08/2018 5:28:44 PM>
<disappeared at 02/08/2018 5:28:46 PM>
TimeStamp: 02/08/2018 5:28:46 PM
<Top 1000 of Best Matches>
no matches found
</Top 1000 of Best Matches>
Contains successfully generated template
</disappeared at 02/08/2018 5:28:46 PM>
</Source 1 - Subject 17>
That's the xml file format and here is my attempt:
protected void Button1_Click(object sender, EventArgs e)
{
string cs = @"Data Source=172.16.6.39;Initial Catalog=FC_SCAN;Persist Security Info=True;User ID=fc_adm;Password=P@ssw0rd";
SqlConnection con = new SqlConnection(cs);
XmlDocument doc = new XmlDocument();
doc.Load("test.xml");
var source = doc.DocumentElement.SelectNodes("Source").Cast<XmlElement>().ToList();
var appeared = source[0].GetAttribute("Appeared");
var disappeared = source[0].GetAttribute("Disappeared");
var top = source[0].GetAttribute("Top");
SqlCommand cmd;
SqlDataAdapter da = new SqlDataAdapter();
string sql = null;
con.Open();
sql = "Insert into Source values ('" + source + "','" + appeared + "','" + disappeared + "','"+top+"')";
cmd = new SqlCommand(sql, con);
da.InsertCommand = cmd;
da.InsertCommand.ExecuteNonQuery();
con.Close();
}
The error console always appears in the xml file, any help, tricks, or hint I would really appreciate.