Well, assuming that you can get the array into this type of array, it would be simple:
Array (
[dirname] => Array (
'Filename 1',
'Filename 2'
),
[dirname] => Array (
'Filename 3',
'Filename 4'
),
[0] => 'Filename',
[1] => 'Filename 2',
[2] => 'Filename 3'
)
You could then do something like this:
<?php
function generateDirectoryXML($directory, $filelist)
{
$xml = '<'.$directory.' name="'.$directory.'">';
foreach($filelist as $dir => $file)
{
// We are dealing with a directory and it's children
if(is_array($file) && is_string($dir))
{
$xml .= generateDirectoryXML($dir, $file);
}
else
{
$xml .= '<file>'.$file.'</file>';
}
}
$xml .= '</directory>';
return $xml;
}
// Assuming the above array is stored in "$filelist" ....
$xml = '<?xml version="1.0" encoding="utf-8"?>
<directoryListing>';
foreach($filelist as $dirname => $file)
{
$xml .= generateDirectoryXML($dirname, $file);
}
$xml .= '</directoryListing>';
echo $xml;
Hope that helps. It's not guaranteed to work 100%; however, it should push in the right direction.