title: C# replace null XML node with respective data type's default value
body: <p>i have to iterate a loop on about 400 different XML files and every time i will be getting different xml file.</p>
  
  <p>I have about 11 nodes in the XML(all coming as <code>String</code>) and i am parsing this XML and storing the XML Element's values using Entity Framework in the Database (in different data types like <code>Decimal</code>, <code>int</code>, <code>string</code>, <code>double</code>)</p>
  
  <p>I do not know which xml node will come as null and i do not want to add a null check for each and every node..</p>
  
  <p><strong><em>Is there a way to implement a common null check for the whole XML file</em></strong> in the loop so if any node comes as null, i can assign it to the default value of respective data type in its respective Entity.. Some thing like the code snippet shown below:-</p>
  
  <pre><code>foreach (XmlNode node in tableElements)
  {
      dcSearchTerm searchTermEntity = new dcSearchTerm();
      //Reference keywords: creation &amp; assignment
      int IDRef = 0, salesRef = 0, visitsRef = 0, saleItemsRef = 0;
      DateTime visitDateRef = new DateTime();
      decimal revenueRef = 0;
  
      int.TryParse(node["id"].InnerText, out IDRef);
      searchTermEntity.SearchTerm = node["Search_x0020_Term"].InnerText;
      searchTermEntity.ReferrerDomain = node["Referrer_x0020_Domain"].InnerText;
  
      if (node["Country"] == null)
      {
          searchTermEntity.Country = "";
      }
      else
      {
          searchTermEntity.Country = node["Country"].InnerText;
      }
  
      DateTime.TryParse(node["Visit_x0020_Date"].InnerText, out visitDateRef);
      searchTermEntity.VisitEntryPage = node["Visit_x0020_Entry_x0020_Page"].InnerText;
      int.TryParse(node["Sales"].InnerText, out salesRef);
      int.TryParse(node["Visits"].InnerText, out visitsRef);
  
      decimal.TryParse(node["Revenue"].InnerText, out revenueRef);
      int.TryParse(node["Sale_x0020_Items"].InnerText, out saleItemsRef);
  
      // assigning reference values to the entity
      searchTermEntity.ID = IDRef;
      searchTermEntity.VisitDate = visitDateRef;
      searchTermEntity.Sales = salesRef;
      searchTermEntity.Visits = visitsRef;
      searchTermEntity.Revenue = revenueRef;
      searchTermEntity.SaleItems = saleItemsRef;
      searches.Add(searchTermEntity);
  
      return searches;
  }
  </code></pre>
  
  <p>P.S.:- This is my first question on SO, please feel free to ask more details 
         Waiting for a flood of suggestions ! :)</p>