title: PHP & XML Read element by attribute value
body: <pre><code>$xml = '&lt;?xml version="1.0"?&gt;
  &lt;entries&gt;
      &lt;response&gt;
          &lt;category&gt;client&lt;/category&gt;
          &lt;action&gt;Greeting&lt;/action&gt;
          &lt;code&gt;1000&lt;/code&gt; 
          &lt;msg&gt;Your Connection with API Server is Successful&lt;/msg&gt; 
          &lt;resData&gt; 
              &lt;data name="svDate"&gt;2010-10-10 02:27:14&lt;/data&gt; 
          &lt;/resData&gt;
      &lt;/response&gt;
  
      &lt;response&gt;
          &lt;category&gt;client&lt;/category&gt;
          &lt;action&gt;Login&lt;/action&gt;
          &lt;code&gt;1000&lt;/code&gt;
          &lt;msg&gt;Command completed successfully&lt;/msg&gt;
          &lt;value&gt;L116:no value&lt;/value&gt;
      &lt;/response&gt;
  
      &lt;response&gt;
          &lt;category&gt;domain&lt;/category&gt;
          &lt;action&gt;InfoDomain&lt;/action&gt;
          &lt;code&gt;1000&lt;/code&gt;
          &lt;msg&gt;Command completed successfully&lt;/msg&gt;
          &lt;value&gt;L125:no value&lt;/value&gt;
          &lt;resData&gt;
              &lt;data name="domain"&gt;google.com&lt;/data&gt;
              &lt;data name="crDate"&gt;2004-12-16&lt;/data&gt;
              &lt;data name="exDate"&gt;2013-12-16&lt;/data&gt;
          &lt;/resData&gt;
      &lt;/response&gt;
  &lt;/entries&gt;';
  
  $xml = simplexml_load_string($xml);
  
  $domain = $xml-&gt;response[2]-&gt;resData[0]-&gt;data[0];
  $crdate = $xml-&gt;response[2]-&gt;resData[0]-&gt;data[1];
  $exdate = $xml-&gt;response[2]-&gt;resData[0]-&gt;data[2];
  </code></pre>
  
  <p>With the above code i can get the values.
  But how can i get the values by attribute value?</p>
  
  <p>For example i want to get the values with something like this:</p>
  
  <pre><code>$domain = $xml-&gt;response[2]-&gt;resData[0]-&gt;data["domain"];
  $crdate = $xml-&gt;response[2]-&gt;resData[0]-&gt;data["crdate"];
  $exdate = $xml-&gt;response[2]-&gt;resData[0]-&gt;data["exdate"];
  </code></pre>
  
  <p>One more question.</p>
  
  <p>If i have two elements with the same name?
  For example i would like to parse the dns. How could i do it?</p>
  
  <p>The xml code is like this:</p>
  
  <pre><code>    &lt;?xml version="1.0"?&gt;
  &lt;entries&gt;
      &lt;response&gt;
          &lt;category&gt;client&lt;/category&gt;
          &lt;action&gt;Greeting&lt;/action&gt;
          &lt;code&gt;1000&lt;/code&gt; 
          &lt;msg&gt;Your Connection with API Server is Successful&lt;/msg&gt; 
          &lt;resData&gt; 
              &lt;data name="svDate"&gt;2010-10-10 02:27:14&lt;/data&gt; 
          &lt;/resData&gt;
      &lt;/response&gt;
  
      &lt;response&gt;
          &lt;category&gt;client&lt;/category&gt;
          &lt;action&gt;Login&lt;/action&gt;
          &lt;code&gt;1000&lt;/code&gt;
          &lt;msg&gt;Command completed successfully&lt;/msg&gt;
          &lt;value&gt;L116:no value&lt;/value&gt;
      &lt;/response&gt;
  
      &lt;response&gt;
          &lt;category&gt;domain&lt;/category&gt;
          &lt;action&gt;InfoDomain&lt;/action&gt;
          &lt;code&gt;1000&lt;/code&gt;
          &lt;msg&gt;Command completed successfully&lt;/msg&gt;
          &lt;value&gt;L125:no value&lt;/value&gt;
          &lt;resData&gt;
              &lt;data name="domain"&gt;google.com&lt;/data&gt;
              &lt;data name="crDate"&gt;2004-12-16&lt;/data&gt;
              &lt;data name="exDate"&gt;2013-12-16&lt;/data&gt;
              &lt;data name="dns"&gt;ns1.google.com&lt;/data&gt;
            &lt;data name="dns"&gt;ns2.google.com&lt;/data&gt;
          &lt;/resData&gt;
      &lt;/response&gt;
  &lt;/entries&gt;
  </code></pre>
  
  <p>As you can see the ns1 and ns2 have the same name. name="dns".
  How can i parse each one in a different variable?</p>
  
  <p>Thank you!</p>