Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. xml Feed

xml Feed

Scheduled Pinned Locked Moved ASP.NET
regexxmlhelpquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jphuphilly
    wrote on last edited by
    #1

    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

    S 1 Reply Last reply
    0
    • J jphuphilly

      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

      S Offline
      S Offline
      siva pinnaka
      wrote on last edited by
      #2

      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

      J 1 Reply Last reply
      0
      • S siva pinnaka

        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

        J Offline
        J Offline
        jphuphilly
        wrote on last edited by
        #3

        Thanks do you have a vb.net version...:-D Da Intern

        S 1 Reply Last reply
        0
        • J jphuphilly

          Thanks do you have a vb.net version...:-D Da Intern

          S Offline
          S Offline
          siva pinnaka
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups