Re: mySQL Results To XML -- my xmltag() functions

From: Date: Sat, 06 Oct 2007 21:14:13 +0000
Subject: Re: mySQL Results To XML -- my xmltag() functions
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-262881@lists.php.net to get a copy of this message
On 10/6/07, Daevid Vincent <daevid@daevid.com> 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);

« previous php.general (#262881) next »