c# - XML document - Object reference not set to an instance of an object -


i'm working on website need google map display positions of members of site.

however, i'm having bit of trouble getting data returned xml document when using http geocode service. when put string browser returns xml fine , if set textbox.text documents innertext displays should. when want extract values nodes, says object reference not set instance of object.

i'm doing way:

string address = m.getproperty("adresse").value.tostring(); string zip = m.getproperty("postnummer").value.tostring(); string city = m.getproperty("by").value.tostring();  xmldocument doc = new xmldocument(); doc.load("http://maps.googleapis.com/maps/api/geocode/xml?address=" + zip + "+" + city + "+" + address + "+dk&sensor=true");  xmlnode latnode = doc.selectsinglenode("geocoderesponse/result/geometry/location/lat/text()"); xmlnode lonnode = doc.selectsinglenode("geocoderesponse/result/geometry/location/lng/text()");  // error occurs when code hits these: string lat = latnode.value; string lon = lonnode.value; 

i must admin haven't worked xml in c# yet, hint appreciated! :-) should above code in foreach loop, looping through members of site.

thanks lot in advance!

all best,

bo

edit: sorry, forgot paste how values! ;)

how did latnode , lonnode ? seems null.

since doing in loop, of members succeed ? perhaps not getting hit of addresses, lat/long nodes in document might not there ?

there no way tell exact problem code posted. use debugger, , step through code see why not getting latnode assigned.

edit

this works:

xmlnode latnode = doc.selectsinglenode("geocoderesponse/result/geometry/location/lat/text()"); xmlnode lonnode = doc.selectsinglenode("geocoderesponse/result/geometry/location/lng/text()"); 

you had little type in path. "code" in "geocoderesponse" should lowercase. xpath case sensitive.


Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -