$path_xml = "convert.xml";
$sxe = simplexml_load_file($path_xml); //load as simpleXML
//print " $sxe->agentname
"; //can access values in tree
//print $sxe->allproperty->aproperty[1]->area . "
"; // take care [0]!
print "";
print "$sxe->agentname";
print "$sxe->email";
print "";
foreach ($sxe->allproperty->aproperty as $oneprop ) // loop through entries
{
$area = $oneprop->area;
$type = $oneprop->type;
$price = $oneprop->price;
$visit = $oneprop->visit;
print "$area $type $price $visit
";
}
//$sxe->aproperty[0]->area = "NewHSCS"; //can change values in tree
//print $sxe->aproperty[0]->area;
// however, cant save updated simpleXML backout out using one php command
// but can convert to text (includes tags) and write to file as XML text
//$mystring = $sxe->asXML(); // can convert Simple XML into string
//print $mystring;
//print " the asXML gives out $def "; //view source in IE
//$outfilepointer = fopen("newXML1.xml","w"); // open for write
//fwrite($outfilepointer, $mystring);
//fclose($outfilepointer);
// We could create a new XML file using data from the XML tree
$outfilepointer = fopen("newFile.xml","w"); // open for write
$outtext .= " \n";
$outtext .= " ".$sxe->agentname." \n";
$outtext .= "" . $sxe->email . " \n";
$outtext .= "";
foreach ($sxe->allproperty->aproperty as $oneprop ) // iterate through entries
{
$area = $oneprop->area;
$type = $oneprop->type;
$price = $oneprop->price;
$visit = $oneprop->visit;
$outtext .= " $area$type$price$visit \n";
}
$path_xml = "secondFileToRead.xml";
$sxe = simplexml_load_file($path_xml); //load as simpleXML
foreach ($sxe->allproperty->aproperty as $oneprop ) // loop through entries
{
$area = $oneprop->area;
$type = $oneprop->type;
$price = $oneprop->price;
$visit = $oneprop->visit;
print "$area $type $price $visit
";
$outtext .= " $area$type$price$visit \n";
}
print "";
$outtext .="";
print "";
$outtext .= "";
fwrite($outfilepointer, $outtext);
fclose($outfilepointer);
?>