Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>$xml = new SimpleXMLElement($xml_string); foreach ($xml-&gt;user as $value) { if ($value-&gt;name == $x &amp;&amp; $value-&gt;lastname-&gt;name == $y) { $attr = $value-&gt;attributes(); echo $attr['url']; } } </code></pre> <p>This will load the xml string into a simple xml object, then compare the node values, and if they match your desired name (<code>$x</code> and <code>$y</code>), print the url. You can also load an xml file instead of string to create the <code>simplexml</code> object if needed. see <code>simplexml</code> documentation for more info.</p> <p>ADDITION</p> <p>Using string (tested and works):</p> <pre><code>&lt;?php $xml_input = &lt;&lt;&lt;XML &lt;user_information&gt; &lt;user url="http://usersweb.com"&gt; &lt;name&gt;Arnold&lt;/name&gt; &lt;lastname&gt; &lt;name&gt;Arnoldson&lt;/name&gt; &lt;/lastname&gt; &lt;age&gt;42&lt;/age&gt; &lt;/user&gt; &lt;user url="http://anotheruserweb.com"&gt; &lt;name&gt;Arnold&lt;/name&gt; &lt;lastname&gt; &lt;name&gt;Arichson&lt;/name&gt; &lt;/lastname&gt; &lt;age&gt;42&lt;/age&gt; &lt;/user&gt;&lt;/user_information&gt; XML; $xml = new SimpleXMLElement($xml_input); foreach ($xml-&gt;user as $value) { if ($value-&gt;name == 'Arnold' &amp;&amp; $value-&gt;lastname-&gt;name == 'Arnoldson') { $attr = $value-&gt;attributes(); echo $attr['url']; } } ?&gt; </code></pre> <p>Using file (should work exact same):</p> <pre><code>&lt;?php $xml = new SimpleXMLElement($xml_file_path, 0, true); foreach ($xml-&gt;user as $value) { if ($value-&gt;name == 'Arnold' &amp;&amp; $value-&gt;lastname-&gt;name == 'Arnoldson') { $attr = $value-&gt;attributes(); echo $attr['url']; } } ?&gt; </code></pre> <p>In the object construct, I added the arguments 0 and true, which allows you to use a file path for the first argument instead of a string. But yes, you could also use the load file function as well.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload