title: How can I avoid NullReferenceExceptions when nodes don't exist in my XML files?
body: <p>I have the following code:</p>
  
  <pre><code>static void Main(string[] args)
  {
      XmlDocument xml = new XmlDocument();
      xml.Load(@"C:\MR.xml");
      XmlNodeList stations = xml.SelectNodes("//FileDump/Message/Attachment");
      var Message_ID = xml.SelectSingleNode("//FileDump/Message/MsgID").InnerXml;
  
      Console.WriteLine("Message ID is :{0}", Message_ID);
  
      foreach (XmlNode station in stations)
      {
          var File_Name = station.SelectSingleNode("FileName").InnerXml;
          var File_ID = station.SelectSingleNode("FileID").InnerXml;
      }
  }
  </code></pre>
  
  <p>FileID and FileName do not always exist in some files. How can I avoid NullReferenceExceptions in this case?</p>