title: Parsing an XML file that can be singleline or multiline
body: <p>I have an XML file that can be one-line:</p>
  
  <pre><code>&lt;webshop&gt;&lt;item&gt;&lt;/item&gt;&lt;item&gt;&lt;/item&gt;&lt;/webshop&gt;
  </code></pre>
  
  <p>or multiline:</p>
  
  <pre><code>&lt;webshop&gt;
      &lt;item&gt;
      &lt;/item&gt;
      &lt;item&gt;
      &lt;/item&gt;
  &lt;/webshop&gt;
  </code></pre>
  
  <p>or mixed:</p>
  
  <pre><code>&lt;webshop&gt;
      &lt;item&gt;&lt;/item&gt;
      &lt;item&gt;&lt;/item&gt;
  &lt;/webshop&gt;
  </code></pre>
  
  <p>Each tag also has a short variant like <code>&lt;webshop/&gt;</code> and <code>&lt;item/&gt;</code> where the tag is opened and closed in one pair of &lt; > brackets. </p>
  
  <p>each tag can appaer any amount of times, but the <code>&lt;item&gt;&lt;/item&gt;</code> or <code>&lt;item/&gt;</code> tag will only appaer inside <code>&lt;webshop&gt;  ...  &lt;/webshop&gt;</code>. Also, the entire xml tag hierarchy is much larger then just these two tags (but I kept it simple for this question), and each tag can have attributes.</p>
  
  <p><strong>I'm trying to parse such an xmlfile using an xmlreader in c#</strong>, but I always run into a problem.</p>
  
  <p>If I try:</p>
  
  <pre><code>while(reader.ReadToFollowing("webshop"))
  {
      Console.WriteLine("webshop");
      //get attributes of webshop tag and do something...
  
      while(reader.ReadToFollowing("item"))
      {
           Console.WriteLine("Item");
          //get attributes of item tag and do something...
      }
  }
  </code></pre>
  
  <p>I never get all the data when the xml is singleline, mixed or the tags close themself (<code>&lt;item/&gt;</code> instead of <code>&lt;item&gt;&lt;/item&gt;</code>). Most of the time, the reader just stops after one instance of <code>&lt;webshop&gt;</code> or <code>&lt;item&gt;</code>  </p>
  
  <p>Is there a robust way to parse this xml, even if the exact lining is not known beforehand? I want to loop over all webshops, and for each webshop loop all over items, and then do something with this data.</p>