title: Parsing XML feed in PHP
body: <pre><code>&lt;?php
  
  $url='http://bart.gov/dev/eta/bart_eta.xml';
  
  $c = curl_init($url);
  
  curl_setopt($c, CURLOPT_MUTE, 1);
  curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
  
  $rawXML = curl_exec($c);
  
  curl_close($c);
  
  $fixedupXML = htmlspecialchars($rawXML);
  
  foreach($fixedupXML-&gt;eta-&gt; as $eta) {
    echo $eta-&gt;destination;
  }
  
  ?&gt;
  </code></pre>
  
  <p>As a way to get introduced to PHP, I've decided to parse BART's XML feed and display it on my webpage. I managed (also via this site) to be able to fetch the data and preserve the XML tags. However, when I try to output the XML data, using what I found to be the simplest method, nothing happens.</p>
  
  <pre><code>foreach($fixedupXML-&gt;eta as $eta){
    echo $eta-&gt;destination;
  }
  </code></pre>
  
  <p>Am I not getting the nested elements right in the foreach loop?</p>
  
  <p>Here is the BART XML feed <a href="http://www.bart.gov/dev/eta/bart_eta.xml" rel="nofollow">http://www.bart.gov/dev/eta/bart_eta.xml</a>
  Thanks!</p>