Question : How do I parse a KML with VB.NET

I need to parse a KML generated by google in vb.net. Does anyone have the code for this?

http://maps.google.com/maps/geo?q=austin,+tx+78730&output=xml&key=abcdefg

Answer : How do I parse a KML with VB.NET

Perhaps the attached will help.

Because the document returned to you has a default namesapce, you MUST supply a prefix, even thought the document doesn't use any prefixes (at least the example doesn't). If you do not supply the prefix both when adding to the XmlNamespaceManager and when calling SelectSingleNode, no node will be selected. I used "anyPrefix" and as the string implies, you can use whatever prefix you like.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim client As New WebClient()
    Dim result As String
    Dim xdoc As New XmlDocument
    Dim mgr As New XmlNamespaceManager(xdoc.NameTable)

    Try
        result = Encoding.UTF8.GetString(client.DownloadData("http://maps.google.com/maps/geo?q=austin,+tx+78730&output=xml&key=abcdefg"))
        xdoc.LoadXml(result)
        mgr.AddNamespace("anyPrefix", "http://earth.google.com/kml/2.0")
        Me.TextBox1.Text = xdoc.SelectSingleNode("/anyPrefix:kml/anyPrefix:Response/anyPrefix:Status/anyPrefix:code", mgr).InnerText
        Me.TextBox2.Text = xdoc.SelectSingleNode("/anyPrefix:kml/anyPrefix:Response/anyPrefix:Status/anyPrefix:request", mgr).InnerText
    Catch
        MsgBox("Unable to download data!")
    End Try
End Sub
Random Solutions  
 
programming4us programming4us