4 Replies - 8519 Views - Last Post: 13 June 2011 - 12:26 PM Rate Topic: -----

#1 John-Ellis  Icon User is offline

  • D.I.C Regular

Reputation: 8
  • View blog
  • Posts: 305
  • Joined: 23-March 10

Loading data from an xml file

Posted 10 June 2011 - 01:36 PM

Hi All,

Im pretty sure im just tired but I think I need some help.

I have an xml file called "QuotesxmlDoc", in my program I have written code for a search screen that searches the xml file for titles or keywords in quotes saved and the information is then shown in a datagridview, please see the code below:

Private Sub btnSearchQoutes_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearchQoutes.Click
        Dim xmlnav As XPathNavigator
        Dim xmlitr As XPathNodeIterator
        Dim speaker As String
        Dim line As String
        Dim dt As New DataTable()
        Dim dr As DataRow
        Dim i As Integer
        DataGridView1.DataSource = New DataView(dt)

        If loaded Then
            xmlnav = QuotesxmlDoc.CreateNavigator()
            xmlitr = xmlnav.Select("//LINE[contains(.,""" & txtBoxSearch.Text & """)]/..")
            dt.Columns.Add("Author", GetType(String))
            dt.Columns.Add("Line", GetType(String))

            While (xmlitr.MoveNext())
                Dim nav2 As Xml.XPath.XPathNavigator = xmlitr.Current.Clone
                nav2.MoveToFirstChild()
                speaker = nav2.Value
                i = 0

                While nav2.MoveToNext()
                    line = nav2.Value
                    dr = dt.NewRow

                    If (i = 0) Then
                        dr(0) = speaker
                    Else
                        dr(0) = ""
                    End If
                    dr(1) = line
                    dt.Rows.Add(dr)
                    i = i + 1
                End While
                DataGridView1.DataSource = New DataView(dt)
            End While
        End If
    End Sub
End Class



On the main screen of the program, I want to show all the saved quotes from the xml file in a datagridview, I just need to show the date, category, author, title of the quotes, I also need the datagridview to refresh everytime a new quote is saved.

Im pretty sure I can use some of the above code to do this but I need a bit of help with it.

Cheers

John

Is This A Good Question/Topic? 0
  • +

Replies To: Loading data from an xml file

#2 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1055
  • View blog
  • Posts: 4,086
  • Joined: 02-July 08

Re: Loading data from an xml file

Posted 10 June 2011 - 01:40 PM

I find much easier to parse with an XmlDocument or Xdocument.
Was This Post Helpful? 1
  • +
  • -

#3 deery5000  Icon User is offline

  • D.I.C Addict

Reputation: 78
  • View blog
  • Posts: 968
  • Joined: 09-May 09

Re: Loading data from an xml file

Posted 10 June 2011 - 04:35 PM

View Posthawkvalley1, on 10 June 2011 - 02:40 PM, said:

I find much easier to parse with an XmlDocument or Xdocument.


Much easier if you use LINQ to XML

:P

Kevin
Was This Post Helpful? 1
  • +
  • -

#4 John-Ellis  Icon User is offline

  • D.I.C Regular

Reputation: 8
  • View blog
  • Posts: 305
  • Joined: 23-March 10

Re: Loading data from an xml file

Posted 12 June 2011 - 09:13 AM

Thanks for the replies, this has helped.

Thanks again

John
Was This Post Helpful? 0
  • +
  • -

#5 John-Ellis  Icon User is offline

  • D.I.C Regular

Reputation: 8
  • View blog
  • Posts: 305
  • Joined: 23-March 10

Re: Loading data from an xml file

Posted 13 June 2011 - 12:26 PM

Ok, after doing some more research I have found this website that shows exactly what I need, if you ever need to load data from an xml file into a datagridview this is a great guide.

http://msdn.microsof...f(v=vs.71).aspx

Cheers

John
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1