Parsing XML with XElement occuring "object reference not set to an instance of the object"
<p><strong>REVISED</strong>:  I restated the question in a simpler thread, and it was answered perfectly. The other thread is:
<a href="http://stackoverflow.com/questions/8177864/how-to-exclude-null-blocks-from-xml-using-linq-to-xml">How to exclude NULL blocks from XML using LINQ-to-XML?</a></p>

<hr>

<p>First, TIA to the stackoverflow community. I have been living here as I work my through this project.</p>

<p>I am struggling with parsing xml (I am a newbie). I have read a lot of examples, and am working from the tutorial here: <a href="http://www.switchonthecode.com/tutorials/introduction-to-linq-simple-xml-parsing" rel="nofollow">http://www.switchonthecode.com/tutorials/introduction-to-linq-simple-xml-parsing</a></p>

<p>XML document is below.</p>

<p>Any suggestions?  </p>

<pre><code>ourdoc = XDocument.Parse(xml);

var arrivalAndDepartures = 
   from arrivalAndDeparture in  ourdoc.Descendants("arrivalAndDeparture")
      select new   // error thrown 2nd time through this block
           {
              routeId = arrivalAndDeparture.Element("routeID").Value,
              scheduledDepartureTime = arrivalAndDeparture.Element("scheduledDepartureTime").Value,
            };

            foreach ( var arrivalAndDeparture in arrivalAndDepartures )
            {  
            Console.WriteLine("routeId: " + arrivalAndDeparture.routeId);
            Console.WriteLine("scheduledDepartureTime: " + arrivalAndDeparture.scheduledDepartureTime);
            };
</code></pre>

<p><img src="http://i.stack.imgur.com/PYAdi.png" alt="This is the error in VS"></p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
&lt;response&gt;
    &lt;version&gt;2&lt;/version&gt;
    &lt;code&gt;200&lt;/code&gt;
    &lt;text&gt;OK&lt;/text&gt;
    &lt;data class="entryWithReferences"&gt;
        &lt;references&gt;
            &lt;agencies&gt;
                &lt;agency&gt;
                    &lt;id&gt;1&lt;/id&gt;
                    &lt;privateService&gt;false&lt;/privateService&gt;
                &lt;/agency&gt;
                &lt;agency&gt;
                    &lt;id&gt;29&lt;/id&gt;
                    &lt;privateService&gt;false&lt;/privateService&gt;
                &lt;/agency&gt;
                &lt;agency&gt;
                    &lt;id&gt;40&lt;/id&gt;
                    &lt;name&gt;Sound Services&lt;/name&gt;
                    &lt;privateService&gt;false&lt;/privateService&gt;
                &lt;/agency&gt;
            &lt;/agencies&gt;
        &lt;entry class="stopWithArrivalsAndDepartures"&gt;
            &lt;stopId&gt;1_450&lt;/stopId&gt;
            &lt;arrivalsAndDepartures&gt;
                &lt;arrivalAndDeparture&gt;
                    &lt;routeId&gt;1_7&lt;/routeId&gt;
                    &lt;scheduledDepartureTime&gt;1321232424000&lt;/scheduledDepartureTime&gt;
                    &lt;predictedDepartureTime&gt;1321232591000&lt;/predictedDepartureTime&gt;
                &lt;/arrivalAndDeparture&gt;
                &lt;arrivalAndDeparture&gt;
                    &lt;routeId&gt;1_36&lt;/routeId&gt;
                    &lt;scheduledDepartureTime&gt;1321232424000&lt;/scheduledDepartureTime&gt;
                    &lt;predictedDepartureTime&gt;1321232608000&lt;/predictedDepartureTime&gt;
                    &lt;tripStatus&gt;
                        &lt;activeTripId&gt;1_18921463&lt;/activeTripId&gt;
                    &lt;/tripStatus&gt;
                &lt;/arrivalAndDeparture&gt;
                &lt;arrivalAndDeparture&gt;
                    &lt;routeId&gt;1_14&lt;/routeId&gt;
                    &lt;scheduledDepartureTime&gt;1321232424000&lt;/scheduledDepartureTime&gt;
                    &lt;predictedDepartureTime&gt;1321232690000&lt;/predictedDepartureTime&gt;
                    &lt;tripStatus&gt;
                        &lt;activeTripId&gt;1_18156836&lt;/activeTripId&gt;
                        &lt;blockTripSequence&gt;24&lt;/blockTripSequence&gt;
                        &lt;serviceDate&gt;1321171200000&lt;/serviceDate&gt;
                    &lt;/tripStatus&gt;
                &lt;/arrivalAndDeparture&gt;
                &lt;arrivalAndDeparture&gt;
                    &lt;routeId&gt;1_39&lt;/routeId&gt;
                    &lt;predictedDepartureTime&gt;1321232939000&lt;/predictedDepartureTime&gt;
                    &lt;tripStatus&gt;
                        &lt;activeTripId&gt;1_18009961&lt;/activeTripId&gt;
                        &lt;blockTripSequence&gt;15&lt;/blockTripSequence&gt;
                    &lt;/tripStatus&gt;
                &lt;/arrivalAndDeparture&gt;
                &lt;arrivalAndDeparture&gt;
                    &lt;routeId&gt;1_23&lt;/routeId&gt;
                &lt;arrivalAndDeparture&gt;
                    &lt;routeId&gt;1_27&lt;/routeId&gt;
                    &lt;scheduledDepartureTime&gt;1321233015000&lt;/scheduledDepartureTime&gt;
                    &lt;tripStatus&gt;
                        &lt;activeTripId&gt;1_18086972&lt;/activeTripId&gt;
                        &lt;blockTripSequence&gt;12&lt;/blockTripSequence&gt;
                    &lt;/tripStatus&gt;
                &lt;/arrivalAndDeparture&gt;
                &lt;arrivalAndDeparture&gt;
                    &lt;routeId&gt;1_16&lt;/routeId&gt;
                    &lt;tripStatus&gt;
                        &lt;activeTripId&gt;1_18009566&lt;/activeTripId&gt;
                        &lt;blockTripSequence&gt;0&lt;/blockTripSequence&gt;
                    &lt;/tripStatus&gt;
                &lt;/arrivalAndDeparture&gt;
                &lt;arrivalAndDeparture&gt;
                    &lt;routeId&gt;1_7&lt;/routeId&gt;
                    &lt;scheduledDepartureTime&gt;1321233324000&lt;/scheduledDepartureTime&gt;
                    &lt;predictedDepartureTime&gt;1321233337000&lt;/predictedDepartureTime&gt;
                    &lt;tripStatus&gt;
                        &lt;activeTripId&gt;1_18921967&lt;/activeTripId&gt;
                        &lt;blockTripSequence&gt;15&lt;/blockTripSequence&gt;
                    &lt;/tripStatus&gt;
                &lt;/arrivalAndDeparture&gt;
            &lt;/arrivalsAndDepartures&gt;
        &lt;/entry&gt;
    &lt;/data&gt;
&lt;/response&gt;
</code></pre>
