tags:

views:

12

answers:

0

I have a php-array, and I need to include the informations in an XML-file. I have tried this:

The array: $files[] = array( "filename"=>$file, "intLatitude"=>$intLatitude, "intLongitude"=>$intLongitude);

       }

I have tried with this:

$file = fopen("results999.xml","w");  
$xml = '<?xml version="1.0" encoding="UTF-8" ?>';  
$xml .= '<metadata>';  
$xml .= '<extensions>';  
$xml .= '<time xmlns="http://www.topografix.com/GPX/gpx_modified/0/1"&gt;2010-04-19T14:49:03.975Z&lt;/time&gt;';
$xml .= '</extensions>';  
$xml .= '</metadata>';                  
for($i = 0; $i < sizeof($files); ++$i)      {  
$xml .= '<extensions>';  
$xml .= '<wpt lat="' . $files[$i]['intLatitude'] .'" lat="' . $files[$i]['intLatitude'] .'">';                
$xml .= '<html>';  
$xml .= '<![CDATA[<a href="http://localhost/gpssql/gpxviewer.php" target="_blank">';  
$xml .= '<img src="'.parseToXML($files[$i]['filename']) .'"';  
$xml .= '/></a>]]>';  
$xml .= '</html>';  
$xml .= '</extensions>';    
$xml .= '</wpt>';    
}  
$xml .= '</gpx>';  
print_r($xml);    

fwrite($file,$xml);  
fclose($file);    

(the value of $i is from an counter ealier) The function:

function parseToXML($htmlStr)
{
$xmlStr=str_replace('<','<',$htmlStr);
$xmlStr=str_replace('>','>',$xmlStr);
$xmlStr=str_replace('"','"',$xmlStr);
$xmlStr=str_replace("'",''',$xmlStr);
$xmlStr=str_replace("&",'&',$xmlStr);
return $xmlStr;
}

I need a XML-file looking like this:

<?xml version="1.0" encoding="UTF-8"?>  
<metadata>  
<extensions>
<time xmls="http//www.topografix.com/GPX/gpx_modified/0/1">2010-04-19T14:49:03975Z</time> 
</extensions>  
</metadata>  
<time>2005-07-17T04:37:17Z</time>   
<wpt lat="55.79854" lon="12.22697">   
<extensions>  
<html>  
<![CDATA[<a href="http://localhost/gpxviewer99.php" target="_blank"><img src="P1030453.jpg" /></a>]]>    
</html>    
</extensions>  
</wpt>  
<wpt lat="55.79011" lon="12.22218">   
<extensions>  
<html>  
<![CDATA[<a href="http://localhost/gpssql/gpxviewer99.php" target="_blank"><img src="P1030450.jpg" /></a>]]>   
</html>  
</extensions>  
</wpt>  

-- and so on.