title: searching XML documents using php
body: <p>I am trying to make a search function using the combination of DOM, PHP and XML. I got something up and running but the problem is that my search function will only accept exact terms, on top of this am wondering if the method I picked the most efficient</p>
  
  <pre><code>$searchTerm = "Lupe";
  $doc = new DOMDocument();
  foreach (file('musicInformation.xml')as $node)
  {
  $xmlString .= trim($node);
  }
  $doc-&gt;loadXML($xmlString);
  $records = $doc-&gt;documentElement-&gt;childNodes;
  
  $records = $doc-&gt;getElementsByTagName("musicdetails");
  foreach( $records as $record )
  {
  $artistnames = $record-&gt;getElementsByTagName("artistname");
  $artistname = $artistnames-&gt;item(0)-&gt;nodeValue;
  
  $recordnames = $record-&gt;getElementsByTagName("recordname");
  $recordname = $recordnames-&gt;item(0)-&gt;nodeValue;
  
  $recordtypes = $record-&gt;getElementsByTagName("recrodtype");
  $recordtype = $recordtypes-&gt;item(0)-&gt;nodeValue;
  
  $formats = $record-&gt;getElementsByTagName("format");
  $format = $formats-&gt;item(0)-&gt;nodeValue;
  
  $prices = $record-&gt;getElementsByTagName("price");
  $price = $prices-&gt;item(0)-&gt;nodeValue;
  
      if($searchTerm == $artistname|| $searchTerm == $recordname || $searchTerm == $recordtype ||$searchTerm == $format || $searchTerm == $price)
      {
       echo "$artistname - $recordname - $recordtype - $format -$price\n";    
      }
  </code></pre>