Friday, August 24, 2012

How can I use xml SelectNodes to parse google maps xml ?

First, save the xml document so you can examine?it?(Your XPath expression makes no sense.)

         string?url?=?"http://maps.google.com/maps/geo?output=xml&key=<your_google_api_key>&q=<city_state>";
          XmlDoc.Load(url);
          XmlDoc.Save(MapPath(@"~\xml\test.xml"));
 
 


Second, get a tool like this one so you can?try different XPath expressions:

Bubba Soft
This site has a great free tool for building XPath Expressions (XPath Builder).

?Third, if you look at the XML, you can see it uses a namespace.? You need to use it like this:

         XmlDocument XmlDoc = new XmlDocument();
          XmlNamespaceManager XmlNs = new XmlNamespaceManager(XmlDoc.NameTable);
 
          XmlNs.AddNamespace("def","http://earth.google.com/kml/2.0");
 
          string url = "http://maps.google.com/maps/geo?output=xml&key=<your_google_api_key>&q=<city_state>";
          XmlDoc.Load(url);
          //XmlDoc.Save(MapPath(@"~\xml\test.xml"));
 
          XmlNodeList Nodes = XmlDoc.SelectNodes("//def:coordinates", XmlNs);
 
          foreach (XmlNode Node in Nodes)
          {
              Response.Write(Node.InnerText + "<br />");
          }
         
 


?

Source: http://forums.asp.net/p/1616099/4138076.aspx/1?How+can+I+use+xml+SelectNodes+to+parse+google+maps+xml+

vesta williams stanford stanford oklahoma state university badgers badgers nbc sports network

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.