title: How can I find the position where a string is malformed XML (in C#)?
body: <p>I'm writing a lightweight XML editor, and in cases where the user's input is not well formed, I would like to indicate to the user where the problem is, or at least where the first problem is.  Does anyone know of an existing algorithm for this?  If looking at code helps, if I could fill in the FindIndexOfInvalidXml method (or something like it), this would answer my question.</p>
  
  <pre><code>using System;
  
  namespace TempConsoleApp
  {
      class Program
      {
          static void Main(string[] args)
          {
              string text = "&lt;?xml version=\"1.0\"?&gt;&lt;tag1&gt;&lt;tag2&gt;Some text.&lt;/taagg2&gt;&lt;/tag1&gt;";
              int index = FindIndexOfInvalidXml(text);
              Console.WriteLine(index);
          }
  
          private static int FindIndexOfInvalidXml(string theString)
          {
              int index = -1;
  
              //Some logic
  
              return index;
          }
      }
  }
  </code></pre>