此代码正常运行!但由于某种原因,它现在停止工作。当我运行这个项目时,下面的代码应该执行,但它不会!请帮忙。
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
答案 0 :(得分:1)
由于您只发布了Form1_Load方法,因此可以确定错误。您还需要在问题中更明确一些;该方法是否完全执行?您是否尝试使用调试器设置断点并逐步执行该方法?
您可能还希望将代码包装在try catch块中,以查看代码是否抛出异常。所以你的代码是:
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
我认为问题可能只在于你的XML文档,所以你可能也想检查一下。