c# - ArgumentNullException while selecting inner node value in xml -


i'm trying location name value xml document given below, shows argumentnullexception . appreciated

    <response xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"     xmlns:xsd="http://www.w3.org/2001/xmlschema" xmlns="http://schemas.microsoft.com/search/local/ws/rest/v1">   <copyright> copyright © 2011 microsoft , suppliers. rights reserved. api cannot accessed , content , results may not used, reproduced or transmitted in manner without express written permission microsoft corporation.   </copyright>   <brandlogouri> http://dev.virtualearth.net/branding/logo_powered_by.png   </brandlogouri>   <statuscode>200</statuscode>   <statusdescription>ok</statusdescription>   <authenticationresultcode>validcredentials</authenticationresultcode>   <traceid> dd31ffaf098f4406b7ecdd0da36680ff   </traceid>       <resourcesets>     <resourceset>       <estimatedtotal>1</estimatedtotal>       <resources>         <location>           <name>1 microsoft way, redmond, wa 98052</name>           <point>             <latitude>47.640568390488625</latitude>             <longitude>-122.1293731033802</longitude>           </point>.... 

this tried

void wc_downloadstringcompleted(object sender, downloadstringcompletedeventargs e)     {          xdocument result = xdocument.parse(e.result);         var ns = result.root.getdefaultnamespace();         var address1 = query in result.descendants(ns + "location")                       select new location                       {                           address = (string)query.element(ns + "name")                       };         location loc = new location();         messagebox.show(loc.address);      } 

i don't see wrong code except this:

location loc = new location(); messagebox.show(loc.address); 

you making new object , trying display loc.address ? ofcourse you'll argumentnullexception

address1 hold result xml making new object.

try this:

first remove line:

location loc = new location(); 

then add this:

foreach (var address in address1) {     messagebox.show(address.address); } 

p.s. next time, important show in question line throwing exception people can see problem is.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -