Parsing an XML Document

Not sure of what I am doing wrong ... I need  to parse this XML document ( Lat and Long from Google)but "g_nodelist" always come to 0 :
the XML response look like this
- <kml xmlns="">
- <Response>
  <name>Batu 3 1/2 Jalan Ipoh,51200 Kuala Lumpur,Malaysia</name>
+ <Status>
- <Placemark id="p1">
  <address>Batu 3 1/2 Jalan Ipoh, Kuala Lumpur, Kuala Lumpur, Malaysia</address>
- <AddressDetails Accuracy="4" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0">
- <Country>
- <AdministrativeArea>
  <AdministrativeAreaName>Kuala Lumpur</AdministrativeAreaName>
- <Locality>
  <LocalityName>Kuala Lumpur</LocalityName>
- <DependentLocality>
  <DependentLocalityName>Batu 3 1/2 Jalan Ipoh</DependentLocalityName>
+ <ExtendedData>
  <LatLonBox north="3.1992447" south="3.1769632" east="101.6969359" west="101.6649211" />
+ <Point>
+ <Placemark id="p2">
  <address>1, Kampung Sungai Gedong, 34400 Bagan Serai, Perak, Malaysia</address>
- <AddressDetails Accuracy="6" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0">
- <Country>
- <Thoroughfare>
- <ExtendedData>
  <LatLonBox north="6.3017400" south="3.2261770" east="101.6721799" west="100.3627141" />
- <Point>
My code :

       Dim g_xml As XmlDocument = New XmlDocument
        Dim g_nodelist As XmlNodeList
        Dim g_node As XmlNode
        g_xml = New XmlDocument()
        'Load the Xml file
        g_xml.Load(" 3 1/2 Jalan Ipoh,51200 Kuala Lumpur,Malaysia&output=xml&key=XXXXXXX-ob")
        'Get the list of name nodes
        g_nodelist = g_xml.SelectNodes("/kml//Response/Placemark")
        'Loop through the nodes
        For Each g_node In g_nodelist
             Dim genderAttribute = g_node.Attributes.GetNamedItem("id").Value
               Dim Coordinate = g_node.ChildNodes.Item(0).InnerText

I must be missing somthing ... I try many different pathfor the name nodes  to no avail. I am open to a different method , I just need to parse the Latitude and longitude  <Point>
, so I it can be stored in a DB .


Who is Participating?
Tony McCreathConnect With a Mentor Technical SEO ConsultantCommented:
You need to handle the namespace in the XML. Here's an article on it:

I've attached a code snippet of the article in in VB.

In your case the namespace is "", so you would probable do something like...

xmlnsManager.AddNamespace("ge", "")

then your xpath would be like this

g_nodelist = g_xml.SelectNodes("/ge:kml//ge:Response/ge:Placemark")
'Instantiate an XmlDocument object.
Dim xmldoc As New System.Xml.XmlDocument()
'Load books.xml into the XmlDocument object. 
'Instantiate an XmlNamespaceManager object. 
Dim xmlnsManager As New System.Xml.XmlNamespaceManager(xmldoc.NameTable)
'Add the namespaces used in books.xml to the XmlNamespaceManager.
xmlnsManager.AddNamespace("bk", "urn:Books")
xmlnsManager.AddNamespace("pub", "urn:Publisher")
Dim MSPressBookList As System.Xml.XmlNodeList
'Execute the XPath query using the SelectNodes method of the XmlDocument.
'Supply the XmlNamespaceManager as the nsmgr parameter.
'The matching nodes will be returned as an XmlNodeList.
'Use an XmlNode object to iterate through the returned XmlNodeList.
MSPressBookList = xmldoc.SelectNodes("//pub:Publisher[. = 'MSPress']/parent::node()/bk:Title", xmlnsManager)
For Each MSPressBook As System.Xml.XmlNode In MSPressBookList

Open in new window

hiramlightAuthor Commented:
Thank's Tiggerito,

it work beautifull , didn't do a lot of XML parsing , so still much to learn .. had to make a small correction with the Nodelist .. correct stament is :

 g_nodelist = g_xml.SelectNodes("/ge:kml//ge:Response/ge:Placemark", xmlnsManager)


Tony McCreathTechnical SEO ConsultantCommented:
Glad you worked it out
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.