i have some data in xml file agent.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<agents>
<agent>
<image> img/sara.jpg</image>
<id>1</id>
<name>Tommy Jenkin</name>
<company>CJenkins Insurance</company>
<street>Insurance150 S State Stree</street>
<city>Linkend</city>
<phone>(773) 561-4331</phone>
</agent>
<agent>
<image> img/primary-nav-logo.png</image>
<id>2</id>
<name>saka</name>
<company>LIC Insurance</company>
<street>Insurance150 S State Stree</street>
<city>Linkend</city>
<phone>(773) 561-4331</phone>
</agent>
</agents>
Now i have one variable called id in php like below
$id = 1
Now i am displaying this xml data with following code
<?php
$xml = simplexml_load_file("agent.xml") or die("Error: Cannot create object");
foreach($xml as $agent){
function processXML($node){
foreach($node->children() as $agent => $data){
$agent= trim($agent);
if($agent=='image')
{
echo '<div><img src="'.$data.'" ></div>';
echo '<div>';
echo '</div>';
}
elseif($agent=='id')
{
echo '<div class = "Left">';
echo '<input type = "button" name="Agent" id = "'.$data.'" class = "subs-btn" value = "Select this Agent" OnClick = Selected(this.id);>';
echo '</div>';
echo '<br/>';
echo '<br/>';
}
else
{
echo '<div class = "inline1">';
echo $data;
echo '</div>';
echo '<br/>';
}
processXML($data);
}
}
processXML($xml);
}
?>
But need a data from xml file having id = 1 so how can i compare it and display it please help