title: Looping Through Nodes In An XML File Using PHP
body: <p>Hi Stackoverflow Community - Question from an enthusiast programmer that I've researched here a great deal but still can't figure out.  Appreciate any help I can get.</p>
  
  <p>I have an XML document called example.xml with the following structure...</p>
  
  <pre><code>&lt;Submissions&gt;
      &lt;Submission&gt;
          &lt;Name&gt;Submission 001&lt;/Name&gt;
          &lt;Entries&gt;
              &lt;Entry&gt;
                  &lt;EntryId&gt;1&lt;/EntryId&gt;
                  &lt;Field1&gt;Foo&lt;/Field1&gt;
              &lt;/Entry&gt;
  
              &lt;Entry&gt;
                  &lt;EntryId&gt;2&lt;/EntryId&gt;
                  &lt;Field1&gt;Bar&lt;/Field1&gt;
              &lt;/Entry&gt;
          &lt;/Entries&gt;
      &lt;/Submission&gt;
      &lt;Submission&gt;
          &lt;Name&gt;Submission 002&lt;/Name&gt;
          &lt;Entries&gt;
              &lt;Entry&gt;
                  &lt;EntryId&gt;1&lt;/EntryId&gt;
                  &lt;Field1&gt;Foo&lt;/Field1&gt;
              &lt;/Entry&gt;
  
              &lt;Entry&gt;
                  &lt;EntryId&gt;2&lt;/EntryId&gt;
                  &lt;Field1&gt;Bar&lt;/Field1&gt;
              &lt;/Entry&gt;
          &lt;/Entries&gt;
      &lt;/Submission&gt;
  &lt;/Submissions&gt;
  </code></pre>
  
  <p>I am using SimpleXML in PHP and would like parse the XML document and echo to the browser something that looks like this:</p>
  
  <pre><code>Submission 1, Entry 1, Foo
  Submission 1, Entry 2, Bar
  Submission 2, Entry 1, Foo
  Submission 2, Entry 2, Bar
  </code></pre>
  
  <p>So basically the idea is just to loop through the XML document and associating every entry with the submission to which it belongs.</p>
  
  <p>I did my research and I'm comfortable getting the entries outputted with the following code, but I can't figure out how to associate the entries with a submission.</p>
  
  <pre><code>&lt;?php
  
  $xml = simplexml_load_file('example.xml');
  
  $Submissions = $xml;
  
  foreach ($Submissions-&gt;Submission-&gt;Entries-&gt;Entry as $Entry) {
  
      echo $Entry-&gt;EntryId.' , '.$Entry-&gt;Field2.' &lt;br /&gt;';
  
  }
  
  ?&gt;
  </code></pre>
  
  <p>Appreciate your help!</p>