user3599604 user3599604 - 1 year ago 83
PHP Question

How can I get a particular node from SimpleXML

My XML is the following:

I would like to get only the 'vetel' value where the 'bank' is mnb.

My PHP is the following:

$xml=simplexml_load_file("") or die("Error: Cannot create object");

$vetel = (string) $xml->valuta->bank->vetel;

Answer Source

This one should be the solution but the problem is, according to your xml file, bank mnb has no vetel. So the iterator can't see bank mnb.

$xml=simplexml_load_file("") or die("Error: Cannot create object");

foreach($xml->valuta->item as $item){
    if($item->bank == "mnb"){
      echo $item->vetel;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download