views:

61

answers:

1

this code was just working! but for some reason it stopped to work now. when i run this project the following code is supposed to execute but it does not! please help.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim xmldoc As New System.Xml.XmlDocument()

    'Load from file

    xmldoc.Load("http://sites.google.com/site/shadchanproject/Home/lots1.xml")

    'Get a list of all the child elements

    Dim nodelist As XmlNodeList = xmldoc.DocumentElement.ChildNodes

    'Parse through all nodes

    For Each outerNode As XmlNode In nodelist

        ListBox1.Items.Add(outerNode.Name)
    Next
End Sub
+1  A: 

Its diffiuclt to be able to say for certain what is wrong since you've only posted the Form1_Load method. You also need to be a bit more explicit in your question; does the method execute at all? Have you tried to set a break point with the debugger and step through the method?

You may also want to wrap your code in an try catch block to see if your code is throwing an exception. So your code would be:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

     Dim xmldoc As New System.Xml.XmlDocument()

     Try
      'Load from file
      xmldoc.Load("http://sites.google.com/site/shadchanproject/Home/lots1.xml")
     Catch ex As Exception
      MessageBox.Show(ex.Message, "Problem loading the document")
     End Try

     Try
      'Get a list of all the child elements
      Dim nodelist As XmlNodeList = xmldoc.DocumentElement.ChildNodes

      'Parse through all nodes
      For Each outerNode As XmlNode In nodelist

       ListBox1.Items.Add(outerNode.Name)
      Next
     Catch ex As Exception
      MessageBox.Show(ex.Message, "Problem with the nodes.")

     End Try
    End Sub

I think the problem may just be with your XML document however so you may want to check that too.

Mark
thanks! you are right i did the TRY thing and it said that there was an invalid character in my XML. is it possible to force VB to read the file even if there is an invalid character?
I__