XML To DB ( WordPress XML)
<pre> <code> SqlConnection conn1 = new SqlConnection(@"Data Source=Eray\sql2012;Initial Catalog=Tiger;User ID=sa;Password=12345Wq"); conn1.Open(); string komut = ""; XmlDataDocument xmldoc = new XmlDataDocument(); XmlNodeList xmlnode; int i = 0; string str = null; FileStream fs = new FileStream(@"C:\Users\Eray\Desktop\erywordpress.xml", FileMode.Open, FileAccess.Read); xmldoc.Load(fs); xmlnode = xmldoc.GetElementsByTagName("item"); for (i = 0; i <= xmlnode.Count - 1; i++) { xmlnode[i].ChildNodes.Item(0).InnerText.Trim(); str = xmlnode[i].ChildNodes.Item(0).InnerText.Trim() + " / " + xmlnode[i].ChildNodes.Item(1).InnerText.Trim() + " / " + xmlnode[i].ChildNodes.Item(6).InnerText.Trim()+xmlnode[i].ChildNodes.Item(2).InnerText.Trim()+xmlnode[i].ChildNodes.Item(6).InnerText.Trim(); Console.WriteLine(str); komut = @" insert into ed_blogsdata (Baslik,Link,Aciklama,Parola,OlusturmaTarihi,Kategori1,Kategori2,Kategori3,Kategori4) values (@title,@link,@veri,@Password,@olusturmatarihi,@kategori1,@kategori2,@kategori3,@Kategori4)"; SqlCommand cmd2 = new SqlCommand(komut, conn1); cmd2.Parameters.AddWithValue("@title", xmlnode[i].ChildNodes.Item(0).InnerText.Trim()); cmd2.Parameters.AddWithValue("@link", xmlnode[i].ChildNodes.Item(1).InnerText.Trim()); cmd2.Parameters.AddWithValue("@veri", xmlnode[i].ChildNodes.Item(6).InnerText.Trim()); if (xmlnode[i].ChildNodes.Item(18)==null) cmd2.Parameters.AddWithValue("@Password", ""); else cmd2.Parameters.AddWithValue("@Password", xmlnode[i].ChildNodes.Item(18).InnerText.Trim()); cmd2.Parameters.AddWithValue("@olusturmatarihi", xmlnode[i].ChildNodes.Item(2).InnerText.Trim()); if (xmlnode[i].ChildNodes.Item(20).InnerText.Trim()==null) { cmd2.Parameters.AddWithValue("@kategori1", ""); } else cmd2.Parameters.AddWithValue("@kategori1", xmlnode[i].ChildNodes.Item(20).InnerText.Trim()); if(xmlnode[i].ChildNodes.Item(21)==null) cmd2.Parameters.AddWithValue("@kategori2", ""); else cmd2.Parameters.AddWithValue("@kategori2", xmlnode[i].ChildNodes.Item(21).InnerText.Trim()); if (xmlnode[i].ChildNodes.Item(22)==null) cmd2.Parameters.AddWithValue("@kategori3",""); else cmd2.Parameters.AddWithValue("@kategori3", xmlnode[i].ChildNodes.Item(22).InnerText.Trim()); if (xmlnode[i].ChildNodes.Item(23)==null) cmd2.Parameters.AddWithValue("@kategori4", ""); else cmd2.Parameters.AddWithValue("@kategori4", xmlnode[i].ChildNodes.Item(23).InnerText.Trim()); cmd2.ExecuteNonQuery(); } Console.ReadLine(); conn1.Close();</code></pre>
0 Yorum