title: Parsing XML with &lt; and &gt;
body: <p>I'm attempting to strip down some XML and get only the value related to a field, however the XML does not use the less than and greater than signs. I try to substring around the field name (in the below case it is Date) and this works fine.</p>
  
  <pre><code>    &amp;lt;my:Date xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2014-07-27T23:04:34"&amp;gt;2014-08-15&amp;lt;/my:Date&amp;gt;
  </code></pre>
  
  <p>However, I am unable to substring around the less than and greater than. My code is as follows:</p>
  
  <pre><code>public string processReportXML(string field, string xml)
      {
          try
          {
              string result = xml.Substring(xml.IndexOf(field));
              int resultIndex = result.LastIndexOf(field);
              if (resultIndex != -1) result = result.Substring(0, resultIndex);
  
              result = result.Substring(result.IndexOf("&amp;gt;"));
              resultIndex = result.IndexOf("&amp;lt;");
              if (resultIndex != -1) result = result.Substring(0, resultIndex);
  
              return field + ": " + result.Substring(4) + "\n";
          }
          catch (Exception e)
          {
              return field + " failed\n";
          }
      }
  </code></pre>
  
  <p>I have tried in a test project and it works fine but I always get the index should be greater than 0 in my actual web service. I have also tried using regex to replace the characters but this also didn't work.</p>
  
  <pre><code>result = Regex.Replace(result, "&amp;(?!(amp|apos|quot|lt|gt);)", "hidoesthiswork?");
  </code></pre>