title: How to get values from mix of namespace and non-namespace XML with
body: <p>Given the XML and related PHP, below how can I get the namespaced values in the same way that I'm able to get the non-namespaced values? I've been referring to a number of other SE QAs about this, but can't seem to get it right.  An help is appreciated. :)</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;rss version="2.0" xmlns:psg="http://b3000.example.net:3000/psg_namespace/"&gt;
    &lt;channel&gt;
      &lt;title&gt;Example&lt;/title&gt;
      &lt;description&gt;example stuff&lt;/description&gt;
      &lt;item&gt;
        &lt;psg:eventId&gt;406589&lt;/psg:eventId&gt;
        &lt;psg:duration&gt;3482&lt;/psg:duration&gt;
      &lt;/item&gt;
    &lt;/channel&gt;
  &lt;/rss&gt;
  
  $xml = new SimpleXMLElement($source, null, true);
  foreach($xml-&gt;channel-&gt;item as $entry){
      echo $entry-&gt;title;          // This works
      echo $entry-&gt;description;    // This works
      echo $entry-&gt;item-&gt;duration  // Pseudo of what I need
  }
  </code></pre>
  
  <p>How to get Duration? My attempts with variations such as this have failed</p>
  
  <pre><code>$namespaces = $item-&gt;getNameSpaces(true);
  $psg = $item-&gt;children($namespaces['psg']);
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <p>While it wasn't the answer I was actually looking for, I have to accept the first answer that got me trying things leading to the actual problem - "operator error"!  This DOES work....my problem was in trying to figure it out, I was debugging with <code>echo print_r($psg, true)</code>.  That was showing the result as a SimpleXmlObject, which then got me chasing how to get those properties - All I had to do was assign the property instead of echoing it.</p>
  
  <pre><code>foreach($xml-&gt;channel-&gt;item as $entry){
      $psg = $item-&gt;children($ns['psg']);
      $title    = (string) $item-&gt;title;
      $duration = (string) $psg-&gt;duration;
  }
  </code></pre>