title: SimpleXML PHP Parsing
body: <p>It IS a duplicate, just not for the question that is was closed for.
  Finally found the answer, even here on SO.
  Actual Duplicate: <a href="https://stackoverflow.com/questions/6027398/php-simplexml-namespace-problem">PHP SimpleXML Namespace Problem</a></p>
  
  <p>EDIT: If you read the question closely, you will see it is NOT a duplicate of <a href="https://stackoverflow.com/questions/2098170/php-namespace-simplexml-problems">PHP namespace simplexml problems</a>. The answer from the 'possible duplicate' is not the answer to my question.</p>
  
  <p>Again:<br/>
  I have no problem with <code>$value = $record-&gt;children('cap', true)-&gt;$title;</code>.(which is all the 'possible duplicate' answers)<br>
  I have a problem when there are other tags inside the tag with the colon.</p>
  
  <pre><code>&lt;tag:something&gt;hello&lt;/tag:something&gt; //I parse out hello (this is the 'duplicate questions' answer that I don't need answered)
  
  &lt;tag:something&gt;
   &lt;stuff&gt;hello&lt;/stuff&gt; //I cannot grab this. Explanation below.
  &lt;/tag:something&gt;
  </code></pre>
  
  <p>END of edit.</p>
  
  <p>ORIGINAL question:<br />
  I cannot get the data inside the tag <code>&lt;value&gt;</code> in the XML located at <a href="http://alerts.weather.gov/cap/us.php?x=1" rel="nofollow noreferrer">http://alerts.weather.gov/cap/us.php?x=1</a> (sample of XML below).</p>
  
  <p>The problem is at:</p>
  
  <p><code>$array[] = $record-&gt;children($tag_cap, true)-&gt;$tag_geocode-&gt;$tag_value;</code></p>
  
  <p>This is the only data I cannot grab, I have verified that all the other data other than <code>$array[4]</code> is grabbed.</p>
  
  <p>There is just a problem getting data from tags when the parent tag is in the form <code>&lt;cap:something&gt;</code>. For example:</p>
  
  <p>I can get 100 when it is like <code>&lt;cap:something&gt;100&lt;/cap:something&gt;</code>. But I cant get 100 if it was like <code>&lt;cap:something&gt;&lt;value&gt;100&lt;/value&gt;&lt;/cap:something&gt;</code>.</p>
  
  <p>Piece of the XML:</p>
  
  <pre><code>&lt;?xml version = '1.0' encoding = 'UTF-8' standalone = 'yes'?&gt;
  
  &lt;feed
  xmlns = 'http://www.w3.org/2005/Atom'
  xmlns:cap = 'urn:oasis:names:tc:emergency:cap:1.1'
  xmlns:ha = 'http://www.alerting.net/namespace/index_1.0'
  &gt;
  &lt;!-- http-date = Tue, 30 Oct 2012 06:34:00 GMT --&gt;
  
  &lt;id&gt;http://alerts.weather.gov/cap/us.atom&lt;/id&gt;
  &lt;logo&gt;http://alerts.weather.gov/images/xml_logo.gif&lt;/logo&gt;
  &lt;generator&gt;NWS CAP Server&lt;/generator&gt;
  &lt;updated&gt;2012-10-30T14:34:00-04:00&lt;/updated&gt;
  &lt;author&gt;
  &lt;name&gt;w-nws.webmaster@noaa.gov&lt;/name&gt;
  &lt;/author&gt;
  &lt;title&gt;Current Watches, Warnings and Advisories for the United States Issued by the    National Weather Service&lt;/title&gt;
  &lt;link href='http://alerts.weather.gov/cap/us.atom'/&gt;
  
  &lt;entry&gt;
  &lt;id&gt;http://alerts.weather.gov/cap/wwacapget.php?x=AK124CCADA8120.BlizzardWarning.124CCAE7BFC0AK.AFGWSWNSB.d32adb45b5c82ec5e486c4cfb96d3fb6&lt;/id&gt;
  &lt;updated&gt;2012-10-30T05:20:00-08:00&lt;/updated&gt;
  &lt;published&gt;2012-10-30T05:20:00-08:00&lt;/published&gt;
  &lt;author&gt;
  &lt;name&gt;w-nws.webmaster@noaa.gov&lt;/name&gt;
  &lt;/author&gt;
  &lt;title&gt;Blizzard Warning issued October 30 at 5:20AM AKDT until October 31 at 6:00AM AKDT by NWS&lt;/title&gt;
  &lt;link href='http://alerts.weather.gov/cap/wwacapget.php?x=AK124CCADA8120.BlizzardWarning.124CCAE7BFC0AK.AFGWSWNSB.d32adb45b5c82ec5e486c4cfb96d3fb6'/&gt;
  &lt;summary&gt;...BLIZZARD WARNING IN EFFECT UNTIL 6 AM AKDT WEDNESDAY... THE NATIONAL WEATHER SERVICE IN FAIRBANKS HAS ISSUED A BLIZZARD WARNING...WHICH IS IN EFFECT UNTIL 6 AM AKDT WEDNESDAY. * VISIBILITY...NEAR ZERO IN SNOW AND BLOWING SNOW. * WINDS...WEST 35 MPH GUSTING TO 50 MPH. * SNOW...ACCUMULATION 3 INCHES THROUGH TONIGHT.&lt;/summary&gt;
  &lt;cap:event&gt;Blizzard Warning&lt;/cap:event&gt;
  &lt;cap:effective&gt;2012-10-30T05:20:00-08:00&lt;/cap:effective&gt;
  &lt;cap:expires&gt;2012-10-30T16:00:00-08:00&lt;/cap:expires&gt;
  &lt;cap:status&gt;Actual&lt;/cap:status&gt;
  &lt;cap:msgType&gt;Alert&lt;/cap:msgType&gt;
  &lt;cap:category&gt;Met&lt;/cap:category&gt;
  &lt;cap:urgency&gt;Expected&lt;/cap:urgency&gt;
  &lt;cap:severity&gt;Severe&lt;/cap:severity&gt;
  &lt;cap:certainty&gt;Likely&lt;/cap:certainty&gt;
  &lt;cap:areaDesc&gt;Eastern Beaufort Sea Coast&lt;/cap:areaDesc&gt;
  &lt;cap:polygon&gt;&lt;/cap:polygon&gt;
  &lt;cap:geocode&gt;
  &lt;valueName&gt;FIPS6&lt;/valueName&gt;
  &lt;value&gt;002185&lt;/value&gt;
  &lt;valueName&gt;UGC&lt;/valueName&gt;
  &lt;value&gt;AKZ204&lt;/value&gt;
  &lt;/cap:geocode&gt;
  &lt;cap:parameter&gt;
  &lt;valueName&gt;VTEC&lt;/valueName&gt;
  &lt;value&gt;/X.NEW.PAFG.BZ.W.0013.121030T1320Z-121031T1400Z/&lt;/value&gt;
  &lt;/cap:parameter&gt;
  &lt;/entry&gt;
  
  ...//rest of XML...
  </code></pre>
  
  <p>PHP Code:</p>
  
  <pre><code>ini_set('display_errors','1');
  
  $alert_url = 'http://alerts.weather.gov/cap/us.php?x=1';
  
  $alert_string_xml = file_get_contents($alert_url);
  
  $alert_simple_xml_object = simplexml_load_string($alert_string_xml);
  
  $count = 0;
  
  $tag_entry = 'entry';
  $tag_summary = 'summary';
  $tag_cap = 'cap';
  $tag_event = 'event';
  $tag_certainty = 'certainty';
  $tag_areaDesc = 'areaDesc';
  $tag_geocode = 'geocode';
  $tag_value = 'value';
  
  foreach ($alert_simple_xml_object-&gt;$tag_entry as $record)
  {
      $count++;
  
      $array = array();
      $array[] = $record-&gt;$tag_summary;
      $array[] = $record-&gt;children($tag_cap, true)-&gt;$tag_event;
      $array[] = $record-&gt;children($tag_cap, true)-&gt;$tag_certainty;
      $array[] = $record-&gt;children($tag_cap, true)-&gt;$tag_areaDesc;
      $array[] = $record-&gt;children($tag_cap, true)-&gt;$tag_geocode-&gt;$tag_value;
      //$array[] = $record-&gt;children($tag_cap, true)-&gt;$tag_geocode-&gt;$tag_value[0]; //doesnt work either
  
  
      echo $array[4]; //nothing is echoed
  
  }
  </code></pre>
  
  <p>MOST CURRENT ATTEMPT:<br />
  I read more on namespaces and understand them better. I even tried what I thought was a better solution:</p>
  
  <pre><code>//inside the above foreach loop
      $namespaces = $record-&gt;getNameSpaces(true);
      $caap = $record-&gt;children($namespaces['cap']);
      echo $caap-&gt;event; //works (but the first way works too)
      echo $caap-&gt;geocode-&gt;value; //(STILL does not work. Nothing is echoed)
  </code></pre>
  
  <p>I don't understand why I cannot grab any data from children tags that have a parent tag that includes a namespace.</p>