Tried a 100 variations of parsing this xml I continually get at this point I though I better make a post before I start breaking things(like my monitor)
System.NullReferenceException was unhandled HResult=-2147467261 Message=Object reference not set to an instance of an object. Source= StackTrace: at Dashboard.Global.geocoder(Object o) in :line 60 at System.Threading.TimerQueueTimer.CallCallbackInContext(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.TimerQueueTimer.CallCallback() at System.Threading.TimerQueueTimer.Fire() at System.Threading.TimerQueue.FireNextTimers() at System.Threading.TimerQueue.AppDomainTimerCallback() InnerException:
The XML is very simple from FCC.gov
<Response xmlns="http://data.fcc.gov/api" status="OK" executionTime="91"> <Block FIPS="181770103002004"/> <County FIPS="18177" name="Wayne"/> <State FIPS="18" code="IN" name="Indiana"/> </Response>
My code has morphed quite a bit
var xdoc = XDocument.Load(response.GetResponseStream()); XNamespace ns = xdoc.Root.Attribute("xmlns").ToString(); var results = xdoc.Element(ns + "Response").Element(ns + "Block").Attribute("FIPS"); //null ref if (xdoc != null) { var FIPS_State_Code = results.Value.Substring(0,1); //null ref var FIPS_County_Code = xdoc.Element("response"); //nullref var Census_Tract = xdoc.Element("response").Element("Block").Attribute("FIPS").Value; //null ref var Census_Block_Group = xdoc.Element("response").Element("Block"); //null ref
No comments:
Post a Comment