xml Feed
-
Hi, I have an xml feed and I want to parse the data so I can get specific items and build a datatable with all the data in it so I can display it in a datagrid. Can someone help me? Sample of XML NM 134434586 74013 15:05:08.493-05:00 125542614 1159 33219895 6.2200 15:05:03.775-05:00 I only want to show, symbol, match price, and match time, thanks for reading. Any help would be helpful. Da Intern
-
Hi, I have an xml feed and I want to parse the data so I can get specific items and build a datatable with all the data in it so I can display it in a datagrid. Can someone help me? Sample of XML NM 134434586 74013 15:05:08.493-05:00 125542614 1159 33219895 6.2200 15:05:03.775-05:00 I only want to show, symbol, match price, and match time, thanks for reading. Any help would be helpful. Da Intern
I am giving code below. This used asp.net 2.0 DataTable dtData = new DataTable(); dtData.Columns.Add(new DataColumn("symbol",typeof(string))); dtData.Columns.Add(new DataColumn("matchPrice",typeof(string))); dtData.Columns.Add(new DataColumn("matchTime",typeof(string))); XmlReaderSettings settings = new XmlReaderSettings(); settings.IgnoreWhitespace = true; settings.IgnoreComments = true; string xmlFile = System.IO.Path.Combine(Request.PhysicalApplicationPath, "test.xml"); using (XmlReader reader = XmlReader.Create(xmlFile, settings)) { while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element && reader.LocalName == "stock") { DataRow row = dtData.NewRow(); row["symbol"] = reader.GetAttribute("symbol"); reader.ReadToFollowing("matchPrice"); row["matchPrice"] = reader.ReadElementContentAsString("matchPrice",""); reader.Read(); row["matchTime"] = reader.Value; dtData.Rows.Add(row); } } } GridView1.DataSource = dtData; GridView1.DataBind(); Thanks
-
I am giving code below. This used asp.net 2.0 DataTable dtData = new DataTable(); dtData.Columns.Add(new DataColumn("symbol",typeof(string))); dtData.Columns.Add(new DataColumn("matchPrice",typeof(string))); dtData.Columns.Add(new DataColumn("matchTime",typeof(string))); XmlReaderSettings settings = new XmlReaderSettings(); settings.IgnoreWhitespace = true; settings.IgnoreComments = true; string xmlFile = System.IO.Path.Combine(Request.PhysicalApplicationPath, "test.xml"); using (XmlReader reader = XmlReader.Create(xmlFile, settings)) { while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element && reader.LocalName == "stock") { DataRow row = dtData.NewRow(); row["symbol"] = reader.GetAttribute("symbol"); reader.ReadToFollowing("matchPrice"); row["matchPrice"] = reader.ReadElementContentAsString("matchPrice",""); reader.Read(); row["matchTime"] = reader.Value; dtData.Rows.Add(row); } } } GridView1.DataSource = dtData; GridView1.DataBind(); Thanks
Thanks do you have a vb.net version...:-D Da Intern
-
Thanks do you have a vb.net version...:-D Da Intern
Dim dtData As DataTable = New DataTable() dtData.Columns.Add(New DataColumn("symbol",Type.GetType(String))) dtData.Columns.Add(New DataColumn("matchPrice",Type.GetType(String))) dtData.Columns.Add(New DataColumn("matchTime",Type.GetType(String))) Dim settings As XmlReaderSettings = New XmlReaderSettings() settings.IgnoreWhitespace = True settings.IgnoreComments = True Dim xmlFile As String = System.IO.Path.Combine(Request.PhysicalApplicationPath,"test.xml") Using reader as XmlReader = XmlReader.Create(xmlFile, settings)) While (reader.Read()) If (reader.NodeType = XmlNodeType.Element And reader.LocalName = "stock" ) Then Dim row As DataRow = dtData.NewRow() row("symbol") = reader.GetAttribute("symbol") reader.ReadToFollowing("matchPrice") row("matchPrice") = reader.ReadElementContentAsString("matchPrice","") reader.Read() row("matchTime") = reader.Value dtData.Rows.Add(row) End If End While End Using GridView1.DataSource = dtData GridView1.DataBind() Thanks, Siva Pinnaka