简体   繁体   English

Visual Basic'System.Xml.XmlException'发生在System.Xml.dll错误中

[英]Visual basic 'System.Xml.XmlException' occurred in System.Xml.dll error

I'm trying to make a code to get the IP GEO information. 我正在尝试编写代码以获取IP GEO信息。

This is my code: 这是我的代码:

Imports System.Xml
Public Class Form1

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

Private Sub geo()
    Dim xmldoc As New XmlDocument
    Dim xmlnode As XmlNodeList
    Dim i As Integer
    xmldoc.Load("http://freegeoip.cnet/xml/" & TextBox1.Text)// this is where I get the Error
    xmlnode = xmldoc.GetElementsByTagName("Respon­se")
    For i = 0 To xmlnode.Count - 1
        Label1.Text = "IP Address : " & xmlnode(i).ChildNodes.Item(0).InnerText.Trim()
        Label2.Text = "Country Code : " & xmlnode(i).ChildNodes.Item(0).InnerText.Trim()
        Label3.Text = "Country Name : " & xmlnode(i).ChildNodes.Item(1).InnerText.Trim()
        Label4.Text = "Region Code : " & xmlnode(i).ChildNodes.Item(2).InnerText.Trim()
        Label5.Text = "Region Name : " & xmlnode(i).ChildNodes.Item(3).InnerText.Trim()
        Label6.Text = "City : " & xmlnode(i).ChildNodes.Item(4).InnerText.Trim()
        Label7.Text = "Zip Code : " & xmlnode(i).ChildNodes.Item(5).InnerText.Trim()
        Label8.Text = "Latitude : " & xmlnode(i).ChildNodes.Item(6).InnerText.Trim()
        Label9.Text = "Longitude : " & xmlnode(i).ChildNodes.Item(7).InnerText.Trim()
        Label10.Text = "Metro Code : " & xmlnode(i).ChildNodes.Item(8).InnerText.Trim()
        xmlnode(i).ChildNodes.Item(9).InnerText.Trim()

    Next

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    geo()
End Sub
End Class

and this is the error message: 这是错误消息:

'System.Xml.XmlException' occurred in System.Xml.dll System.Xml.dll中发生了'System.Xml.XmlException

Anyone knows why? 有人知道为什么吗?

You are not passing the correct parameters to the website. 您没有将正确的参数传递给网站。 Below is an example of data returned from freegeoip. 以下是从freegeoip返回的数据的示例。

Imports System.Xml
Module Module1

    Sub Main()
        Dim input As String =
            "<?xml version=""1.0"" encoding=""UTF-8""?>" & _
               "<Response>" & _
                  "<IP>123.123.123.123</IP>" & _
                  "<CountryCode>CN</CountryCode>" & _
                  "<CountryName>China</CountryName>" & _
                  "<RegionCode>11</RegionCode>" & _
                  "<RegionName>Beijing Shi</RegionName>" & _
                  "<City>Beijing</City>" & _
                  "<ZipCode/>" & _
                  "<TimeZone>Asia/Shanghai</TimeZone>" & _
                  "<Latitude>39.929</Latitude>" & _
                  "<Longitude>116.388</Longitude>" & _
                  "<MetroCode>0</MetroCode></Response>"
        Dim xmldoc As New XmlDocument
        xmldoc.LoadXml(input)

    End Sub

End Module​

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C#Xml System.Xml.dll中发生了类型为&#39;System.Xml.XmlException&#39;的未处理的异常 - C# Xml An unhandled exception of type 'System.Xml.XmlException' occurred in System.Xml.dll System.Xml.dll中发生“ System.Xml.XmlException”,但未在用户代码中处理 - 'System.Xml.XmlException' occurred in System.Xml.dll but was not handled in user code EntityFramework.dll中出现“System.Xml.XmlException”类型的异常,但未在用户代码中处理 - An exception of type 'System.Xml.XmlException' occurred in EntityFramework.dll but was not handled in user code 使用LINQ to XML时出现System.Xml.XmlException错误 - System.Xml.XmlException error upon using LINQ to XML System.Xml.dll中发生&#39;System.InvalidOperationException&#39; - 'System.InvalidOperationException' occurred in System.Xml.dll 如何捕获system.xml.xmlexception - How to catch system.xml.xmlexception System.Xml.XmlException-根元素丢失 - System.Xml.XmlException - Root element is missing W8电话System.Xml.XmlException& - W8 Phone System.Xml.XmlException & System.Xml.XmlException与dotnet测试一起发生 - System.Xml.XmlException occurs with dotnet test System.Xml.XmlException:解析名称时发生了意外的文件结尾 - System.Xml.XmlException: Unexpected end of file while parsing Name has occurred
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM