title: PHP XMLReader read , edit Node , write XMLWriter
body: <p>I have an XML file which is very very large (millions of records). Due to speed and memory constraints I plan to use <code>XMLReader</code>/<code>XMLWriter</code>. </p>
  
  <p>I need to read the file, getting one record, change its attribute, and finally save XML again.</p>
  
  <p>For testing I created an XML file and write some records into it using these lines:</p>
  
  <pre><code>$doc = new XMLWriter();  
  $doc-&gt;openURI($xmlFile);  
  $doc-&gt;startDocument('1.0','UTF-8');  
  $doc-&gt;setIndent(4);   
  $doc-&gt;startElement('DBOS'); 
  for($r=0;$r&lt;10; $r++){
      $doc-&gt;startElement('ITEMS');
      for($i=0;$i&lt;5; $i++){
          $doc-&gt;startElement('ITEM');  
          $doc-&gt;writeAttribute('id', $r.'-'.$i);
          $doc-&gt;endElement();
      }
      $doc-&gt;endElement();
  }
  $doc-&gt;endElement();  
  $doc-&gt;endDocument();   
  $doc-&gt;flush();
  </code></pre>
  
  <p>I read it again using this:</p>
  
  <pre><code>$reader = new XMLReader();
  if (!$reader-&gt;open($xmlFile)){
      die("Failed to open 'data.xml'");
  }
  while($reader-&gt;read()){
      if ($reader-&gt;nodeType == XMLReader::ELEMENT &amp;&amp; $reader-&gt;name == 'ITEMS') {
          $node = $reader-&gt;expand();
          $items = $node-&gt;childNodes;
          foreach ($items as $ik =&gt; $itm ){
              print $itm-&gt;textContent.'&lt;br/&gt;';
              // how to change the ID Attribute of a Node (DomNode) and save changes to the original XML File 
          }
          break;
      }
  }
  $reader-&gt;close();
  </code></pre>
  
  <p><strong>My question</strong>: How to change the <code>id</code> attribute of a <code>DomNode</code> and save changes to the original XML File <strong>using XMLWriter</strong> again?</p>