On 10/6/07, Daevid Vincent <[EMAIL PROTECTED]> wrote:
> Here's the 'functions_xml.inc.php' file I use, it has served me well and
> handles I believe all tag cases, personally I'm a big fan of using the
> attributes as they're most easily parsed out in the PHP DOM functions:
I made this at one point:
function array2xml($array, $complete = true) {
$xml = "<$array[NODE] ";
unset($array['NODE']);
ksort($array);
foreach(array_keys($array) as $key) {
$xml .= "$key=\"$array[$key]\" ";
}
if($complete) {
$xml .= "/";
}
$xml .= ">";
return $xml;
}
it takes an associative array with a key of "NODE" for the node name
and makes it a single xml node with all the content in attributes. it
even alphabetizes the attributes. special preparing of the data (like
htmlspecialchars()) might be needed to ensure XML compliance.
i made one to translate it into nodes, but i think at the time i read
that attribute parsing is quicker.
calling it looks like this:
$context['NODE'] = "context-info";
$context['current-datetime'] = format_time_xml(time(),"UTC");
$context['current-hostname'] = $_SERVER['HTTP_HOST'];
$context['current-page'] = $_SERVER['PHP_SELF'];
$xml = array2xml($context);
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php