title: Retrieving multiple XML tags based on child tags?
body: <p>I have an XML structure where multiple tags share the same name, and need to process it using PHP.</p>
  
  <p>I'm using the SimpleXMLElement PHP class (<a href="http://php.net/manual/en/class.simplexmlelement.php" rel="nofollow">http://php.net/manual/en/class.simplexmlelement.php</a>) to achieve this.</p>
  
  <p>An example of the XML I need to process would be:</p>
  
  <pre><code>&lt;parent&gt;
      &lt;child&gt;
          &lt;attribute&gt;
              &lt;name&gt;hair&lt;/name&gt;
              &lt;value&gt;blond&lt;/value&gt;
          &lt;/attribute&gt;
          &lt;attribute&gt;
              &lt;name&gt;height&lt;/name&gt;
              &lt;value&gt;1.2m&lt;/value&gt;
          &lt;/attribute&gt;
          &lt;attribute&gt;
              &lt;name&gt;weight&lt;/name&gt;
              &lt;value&gt;35kg&lt;/value&gt;
          &lt;/attribute&gt;
      &lt;/child&gt;
  &lt;/parent&gt;
  </code></pre>
  
  <p>And then I'm processing the data using something like this in PHP:</p>
  
  <pre><code>$data = get_data();
  $xml = simplexml_load_string($data);
  foreach($xml as $child) {
       $hairColour = $child-&gt;Attribute[0]-&gt;value);
       $height = $child-&gt;Attribute[1]-&gt;value);
       $wegith = ($child-&gt;Attribute[2]-&gt;value);
       // do stuff with data
  }
  </code></pre>
  
  <p>The thing is, I'd really rather not get Attributes by their order, as it's possible this could change in the future. I'd much rather get the attributes by their name, so something like (I realise this doesn't work, but it's a great example of what I'm trying to achieve):</p>
  
  <pre><code>$data = get_data();
  $xml = simplexml_load_string($data);
  foreach($xml as $child) {
       $hairColour = $child-&gt;Attribute('hair')-&gt;value);
       $height = $child-&gt;Attribute('height')-&gt;value);
       $wegith = ($child-&gt;Attribute('weight)-&gt;value);
       // do stuff with data
  }
  </code></pre>
  
  <p>Is this actually possible? I can't seem to find anything in the documentation relating to this.</p>