title: Parse XML data using php
body: <p>Here is an xml example that I load from an external xml file 
  $data = file_get_contents($filename);
  $dom->loadXML($data);  </p>
  
  <p>Using php, I want to walk through this xml to get the title, question, and each question's choices.   </p>
  
  <pre><code>&lt;questions&gt;
      &lt;record topic = "classic video games"&gt;
          &lt;title&gt;Centipede&lt;/title&gt; 
          &lt;question&gt;How many shots does it take to destroy a mushroom?&lt;/question&gt; 
          &lt;choices&gt;
              &lt;choice correct="no" votes="0"&gt;1&lt;/choice&gt;
              &lt;choice correct="no" votes="0"&gt;2&lt;/choice&gt;
              &lt;choice correct="no" votes="0"&gt;3&lt;/choice&gt;
              &lt;choice correct="yes" votes="0"&gt;4&lt;/choice&gt;
          &lt;/choices&gt;
      &lt;/record&gt;
      &lt;record topic = "classic video games"&gt;
          &lt;title&gt;Quake&lt;/title&gt;
          &lt;question&gt;What is the name of the most powerful weapon in Quake?&lt;/question&gt;
          &lt;choices&gt;
              &lt;choice correct="no" votes="0"&gt;gauntlet&lt;/choice&gt;
              &lt;choice correct="no" votes="0"&gt;machine gun&lt;/choice&gt;
              &lt;choice correct="yes" votes="0"&gt;BFG2000&lt;/choice&gt;
              &lt;choice correct="no" votes="0"&gt;rocket launcher&lt;/choice&gt;
              &lt;choice correct="no" votes="0"&gt;railgun&lt;/choice&gt;
          &lt;/choices&gt;
      &lt;/record&gt;
  &lt;/questions&gt;
  </code></pre>
  
  <p>I want my result to be like this:</p>
  
  <pre><code>Title = Centipede
  
  Question = How many shots does it take to destroy a mushroom?
  
  I. 1
  II. 2
  III. 3
  IV. 4
  </code></pre>
  
  <p>here is my try:</p>
  
  <pre><code>$dom-&gt;loadXML($data);
  
  
      $all_records = $dom-&gt;getElementsByTagName("record");
          $all_choices = $dom-&gt;getElementsByTagName("choices"); 
          foreach($all_records as $record){
          $question = $record-&gt;getElementsByTagName("question")-&gt;item(0)-&gt;nodeValue;
          $title = $record-&gt;getElementsByTagName("title")-&gt;item(0)-&gt;nodeValue;
          echo "&lt;h2&gt; Title=$title&lt;/h2&gt;";
                  echo "&lt;h5&gt;&lt;em&gt;Question=$question&lt;/em&gt;&lt;/h5&gt;";
                  echo "&lt;li&gt;". $all_choices-&gt;getElementsByTagName("choice")-&gt;nodeValue."&lt;/li&gt;\n";
  
          echo "&lt;/ul&gt;\n";
          echo "&lt;/div&gt;\n";
  
      }
  </code></pre>
  
  <p>I'm able to get the title and the question, but not the choices! </p>