title: Dynamically read record of XML file in PHP
body: <p>I have records in XML format. I have 10 different xml records. Now I want php function to read XML record dynamically. </p>
  
  <p>I have created method but it works for single type of xml. My code is :</p>
  
  <pre><code>function readXMLDoc($xml_file){
      $xmlDoc = new DOMDocument();
      $res = $xmlDoc-&gt;load('uploads/xml_records/'.$xml_file);
  
      if (!$res) {
          echo("Failed to parse XML\n");
          return false;
      }
  
      $events = $xmlDoc-&gt;getElementsByTagName("photoSet");
      $data= array();
      foreach($events as $key=&gt;$event):       
           $dates = $event-&gt;getElementsByTagName("desc");
           $data[$key]['desc'] = $dates-&gt;item(0)-&gt;nodeValue;
  
           $venues = $event-&gt;getElementsByTagName("set");
           $data[$key]['set'] = $venues-&gt;item(0)-&gt;nodeValue;
  
           $names = $event-&gt;getElementsByTagName("number");
           $data[$key]['number'] = $names-&gt;item(0)-&gt;nodeValue;
  
           $names = $event-&gt;getElementsByTagName("thumb");
           $data[$key]['thumb'] = $names-&gt;item(0)-&gt;nodeValue;
      endforeach;  
      return $data;
  } 
  </code></pre>
  
  <p>I want dynamically, get node name and value.</p>