title: Try-Catch statement ends While loop reading through an XML file in C#
body: <p>I have a while loop going through an XML file, and for one of the nodes "url", there are sometimes invalid values within it. I put a try-catch statement around this to catch any invalid values. The problem is, whenever an invalid value is grabbed the while loop is killed and the program continues on outside of that loop. I need the while loop to continue reading through the rest of the XML file after an invalid value if found. </p>
  
  <p>Here is my code:</p>
  
  <pre><code>        XmlTextReader reader = new XmlTextReader(fileName);
          int tempInt;
  
          while (reader.Read())
          {
              switch (reader.Name)
              {
                  case "url":
                      try
                      {
                          reader.Read();
                          if (!reader.Value.Equals("\r\n"))
                          {
                              urlList.Add(reader.Value);
                          }
                      }
                      catch
                      {                            
                          invalidUrls.Add(urlList.Count);   
                      }
                      break;
              }
          }
  </code></pre>
  
  <p>I chose not to include the rest of the switch statement as it is not relevant. Here is a sample of my XML:</p>
  
  <pre><code>&lt;?xml version="1.0"  encoding="ISO-8859-1" ?&gt;
  &lt;visited_links_list&gt;
      &lt;item&gt;
          &lt;url&gt;http://www.grcc.edu/error.cfm&lt;/url&gt;
          &lt;title&gt;Grand Rapids Community College&lt;/title&gt;
          &lt;hits&gt;20&lt;/hits&gt;
          &lt;modified_date&gt;10/16/2012 12:22:37 PM&lt;/modified_date&gt;
          &lt;expiration_date&gt;11/11/2012 12:22:38 PM&lt;/expiration_date&gt;
          &lt;user_name&gt;testuser&lt;/user_name&gt;
          &lt;subfolder&gt;&lt;/subfolder&gt;
          &lt;low_folder&gt;No&lt;/low_folder&gt;
          &lt;file_position&gt;834816&lt;/file_position&gt;
       &lt;/item&gt;
  &lt;/visited_links_list&gt;
  </code></pre>
  
  <p>The exception I get throughout the code is similar to the following: </p>
  
  <p><strong>"' ', hexadecimal value 0x05, is an invalid character. Line 3887, position 13."</strong></p>