title: Parse & query XML file
body: <p>I am using the below code in PHP to parse a XML file and retrieve a certain information from the file.</p>
  
  <pre><code>$dom    = new DOMDocument();
  $xpath  = new DOMXPath($dom);
  $reader = new XMLReader();
  $reader-&gt;open('File.xml');
  while ($reader-&gt;read()) {
      if ($reader-&gt;nodeType == XMLReader::ELEMENT &amp;&amp; $reader-&gt;name == 'Hotel') {
          $node = $dom-&gt;importNode($reader-&gt;expand(), true);
          $dom-&gt;appendChild($node);
          $h1name = $xpath-&gt;evaluate('string(/Hotel[HotelCode = "'.$hotelCodes[0].'"]/HotelName)', $node);
          $dom-&gt;removeChild($node);
          if ($h1name) {
           $reader-&gt;close();
           break;
          }
      }
  }
  </code></pre>
  
  <p>I am using a VPS with CENTOS x64 , SSD drive, 1GB of ram and a 1.8 ghz CPU.
  The code works but is very slow.
  If i parse a 20 mb file it takes ~1 minute fo the page to load.</p>
  
  <p>Could you please help to improve the code so i can get a faster working solution ?</p>