title: PHP - Read and repair big invalid XML files
body: <p>I have to read some quite heavy XML files (between 200 MB and 1 GB) that are, for some of them, invalid. Let me give you a small example : </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;rss xmlns:g="http://base.google.com/ns/1.0" version="2.0"&gt;
    &lt;item&gt;
      &lt;title&gt;Some article&lt;/title&gt;
      &lt;g:material&gt;&lt;ul&gt;&lt;li&gt;50 % Coton&lt;/li&gt;&lt;li&gt;50% Lyocell&lt;/li&gt;&lt;/g:material&gt;
    &lt;/item&gt;
  &lt;/rss&gt;
  </code></pre>
  
  <p>Obviously, there is a missing <code>&lt;/ul&gt;</code> closing tag in the <code>g:material</code> tag. Moreover, people that have developed this feed should have enclosed <code>g:material</code> content into <code>CDATA</code>, which they did not... Basically, that's what I want to do : add this missing <code>CDATA</code> section.</p>
  
  <p>I've tried to use a SAX parser to read this file but it fails when reading the <code>&lt;/g:material&gt;</code> tag since the <code>&lt;/ul&gt;</code> tag is missing. I've tried with XMLReader but got basically the same issue.
  I could probably do something with DomDocument::loadHtml but the size of this file is not really compatible with a DOM approach.
  Do you have any idea how I could simply repair this feed without having to buy lots of RAM for DomDocument to work ?
  Thanks.</p>