title: PHP XML DomDocument - Pulling attributes and child attributes
body: <pre><code>&lt;tle-type name="Channel" tag="47" mt="true"&gt;
    &lt;tle-field name="ChannelId" tag="1" type="String" minOccurs="1" maxOccurs="1"&gt;
      Description 1.
    &lt;/tle-field&gt;           
    &lt;tle-field name="resultCode" tag="2" enum="true" type="ChannelResult" minOccurs="1" maxOccurs="1"&gt;     
      Description 2.
    &lt;/tle-field&gt;
    &lt;tle-field name="jid" tag="3" type="String" minOccurs="0"  maxOccurs="1"&gt;
      Description 3.
    &lt;/tle-field&gt;
    &lt;tle-field name="thing" tag="4" type="String" minOccurs="0"  maxOccurs="1"&gt;
      Description 5.
    &lt;/tle-field&gt;
  &lt;/tle-type&gt;
  </code></pre>
  
  <p>Above is a section of XML that I am dealing with.  The 'tag' attribute under 'tle-type' is the unique identifier and then in it's children 'tle-field' will be another 'tag' attribute.  I'm essentially looking for a way to identify the first 'tag' 'tle-type', then create a $attribute = "value" out of 'tle-field', with the description in $desc.</p>
  
  <p>While I can pull out the 'tle-type' attribute with tag="x", I cannot seem to pull the child attributes out where the tag = 'y'.  I can just print all the attributes.</p>
  
  <pre><code>foreach ($xml-&gt;getElementsByTagName('tle-type') as $tag) {
          if($tag-&gt;getAttribute('tag') === '47') {
                  foreach ($tag-&gt;childNodes as $child ) { 
                          foreach ($child-&gt;attributes as $t ) {                                                                                        
                                  echo "&lt;BR&gt;".$t-&gt;nodeName." = ".$t-&gt;nodeValue;
  
                          }   
                  }   
          }   
  }
  </code></pre>
  
  <p>With the above, I end up with Warning: Invalid argument supplied for foreach() in file.php on line 4:</p>
  
  <pre><code>foreach ($child-&gt;attributes as $t)
  </code></pre>
  
  <p>Yet the attribute names and values show up, minus the description, of course.  I hope I've explained this alright...  </p>
  
  <p>Any assistance would be appreciated!</p>