snippets / Read XML file and Iterate through Rows

Language: Visual Basic .Net - First posted by Tlaloc on 2008-01-3 19:50 (9 months)
Link to the snippet: http://www.friendsnippets.org/snippet/132/

You can call this function on Page load like this: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

ReadXMLFile()

End Sub

 1 Function ReadXMLFile()        
2 Dim strBuilder As StringBuilder = New StringBuilder() 'Read XML File
3 Dim ds As New DataSet()
4 ds.ReadXml("C:\Website\XMLMadness\App_Data\USA.xml") 'Iterate through the tables in DataSet.
5 Dim dt As DataTable
6 dt = ds.Tables(0) 'Iterate through the rows in a table.
7 Dim n As Integer
8 For n = 0 To dt.Rows.Count - 1 'Do stuf to your data here.
9 'strBuilder.Append(dt.Rows(n)(1) & vbCrLf)
10 strBuilder.Append(dt.Rows(n)(1) & "<br />")
11 'strBuilder.Append(Chr(34) & dt.Rows(n)(0) & Chr(34) & "<br />")
12 'Get a different column
13 'strBuilder.Append(Chr(34) & dt.Rows(n)(1) & Chr(34) & "<br />")
14 Next
15 Literal1.Text = strBuilder.ToString
16 Return strBuilder.ToString()
17 End Function
In order to post a comment, you should have a friendsnippet account. Please sign-in.

0 comments

Jan '08
  • You can call this function on Page load like this: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load ReadXMLFile() End Sub

Common Tags



snippet History

Jan '08