I needed a quick, perhaps even sloppy way to output an array as XML. Some Googling turned up a few tools, including Simon Willison’s XmlWriter, Johnny Brochard’s Array 2 XML, Roger Veciana Associative array to XML, and Gijs van Tulder’s Array to XML. Finally, Gijs also pointed me to the XML_Serializer PEAR Package.
In an example of how even the smallest barriers can turn people away, I completely ignored the two possible solutions at PHP Classes, because navigating and using the site sucks. I passed on Willison’s function because, well, it didn’t look like it would do enough of what I wanted. Despite Gijs’ recommendation of the PEAR module, I was happy enough to use his array_to_xml function, as it did what I needed and required the lest work for the moment. I may revisit XML_Serializer sometime, but…
array, array to xml, php, xml, XML_Serializer
Posted September 18, 2006 by Casey Bisson
Categories: Technology. Tags: array, array to xml, php, xml, XML_Serializer.
4 Comments
Comments RSS
TrackBack Identifier URI
User contributed tags for this post:
php array to xml (4191) - array to XML PHP (948) - php array xml (368) - php xml to array (255) - xml to array php (183) - php output xml from array (160) - array to xml (88) - php array 2 xml (74) - php5 array to xml (73) - array xml php (60) - php xml array (56) - array to xml in php (54) - php5 xml to array (50) - convert PHP array to XML (45) - php array (42) - xml php array (40) - php array into xml (39) - xml array php (37) - xml to php array (35) - F (32) - array 2 xml (26) - xml to array php5 (25) - php convert array to xml (23) - php5 array xml (21) - xml 2 array (20) - array to xml php5 (19) - php xml 2 array (17) - php to xml converter (17) - php arrays to xml (17) - xml to array (16) - php array in xml (15) - php associative array to xml (15) - Array (15) - convert array to xml php (15) - PHP Array_To_XML (14) - pear array to xml (13) - array 2 xml php (13) - php xml from array (13) - php array para xml (13) - convert xml to array php (13) - convert php array xml (13) - array_to_xml php (12) - php4 array to xml (11) - php5 associative array to xml (11) - xml to array in php (11) - array php XML (10) - best XML to array PHP (10) - array_to_xml (10) - php5 convert array to xml (10) - php array as xml (10) - PHP 5 array to xml (10) - xml php5 loop (10) - php create xml from array (10) - php5 array (9) - php4 xml to array (9) - array a xml php (8) - php array to dom (8) - array-to-xml php (8) - array xml (8) - php pear xml to array array to xml (7) - associative array to xml (7) - PHP convert associative array to xml (7) - pear xml to array (7) - php xml to associative array (7) - array to XML using php (7) - php array to xml domdocument (6) - php5 xml array (6) - php5 2 xml (6) - php array to xml class (6) - array to xml with php (6) - DOMDocument to array (6) - xml array (6) - DOMdocument array (5) - php 5 xml 2 array (5) - php array to xml associative (5) - array to xml domdocument (5) - array php5 (5) - convert array to xml in php (5) - xml 2 array php (5) - xml to array php4 (5) - DOM TO ARRAY PHP (5) - rss feeds php array (5) - convert php to xml (5) - php msn xml (5) - array to xml php 5 (5) - php array from xml (5) - convert xml to php array (5) - array to xml php class (5) - XML Array appendChild (4) - php 2 xml (4) - php4 xml array (4) - PHP class array to XML (4) - php5 array as xml (4) - php5 convert xml to array (4) - php 5 xml to array (4) - php XmlWriter array to xml (4) - php array als xml (4) - convert array to xml generate in php (4) - array to xml pear (4) - xml php5 array (4) - xml to array php array to xml (4) - php from array to xml (4) - xml to array to xml php (4) - php array to xml conversion (4) - array in XML php (4) - php convert array xml (4) - Array XML php5 (4) - php class generate-xml from array (4) - php: array to xml (4) - php, array to xml (4) - php array to xml simple (4) - php xml arrays (4) - convert associative array to xml simplexml (4) - post xml php (4) - array to dom php (4) - php create array from xml (4) - convert array to xml php5 (4) - array to xml simplexml (4) - xml from php array (4) - associative array to xml php (3) - php arry to xml (3) - output array as xml php (3) - XML Serializer xml to array (3) - php array to simple xml (3) - convert array to xml (3) - Output XML from PHP Array (3) - php convert xml array (3) - xml to php (3) - php dom vs xmlwriter (3) - php 5 convert xml to array (3) - php xml to array class (3) - convert xml to php (3) - php xml create array (3) - php convert array into xml (3) - php array to from xml (3) - xml to array using php (3) - XML_Serializer array (3) - DOMDocument array php (3) - php xml append (3) - create xml from array php (3) - php arrays and xml (3) - php xml post (3) - php (3) - php array to xml dom (3) - php generate xml from array (3) - pear array_to_xml (3) - xml to array with php (3) -
I agree with you on phpclasses.org; it appears a little bit too informal for my liking — and while the rather strict coding standards that PEAR requires for acceptance of packages can be a barrier for the contributing developer, I’ve found in my ongoing development for File_MARC (http://marc.coffeecode.net) that those guidelines have really increased my faith in the general quality of the code maintained by the PEAR project. The review comments I have received so far have already helped improve my package proposals.
[tags]PEAR[/tags]
I suggest taking a look at the PEAR package, it may be a bit heafty, but it is very worth while.
[tags]PEAR, XML_Serializer[/tags]
May nbe this code fragment helps!
function array_to_xml($aArr, $sName, &$item = null) {
global $dom;
if (is_null($item))
$item = $dom->createElement($sName);
// Loop thru each element
foreach ($aArr as $key => $val) {
if (is_array($val)) {
//
$sub = $dom->createElement($key);
$item->appendChild($sub);
array_to_xml($val, $key, $sub);
} else {
// Add this item
$sub = $dom->createElement($key, $val);
$item->appendChild($sub);
}
}
return $item;
}
$dom = new DOMDocument(’1.0′);
// create root element
$root = $dom->createElement(’bsr’);
$dom->appendChild($root);
// create child element
$info = $dom->createElement(’info’);
$root->appendChild($info);
$aRes = array(
‘first’=>3,
’subarray’=> array(
’sub1′=>’sub1′,
’sub2′=>’sub2′,
’sub3′=>’sub3′
)
‘last’
};
$restree = array_to_xml($aRes, ‘result’);
$info->appendChild($restree);
I’m surprised that nobody responded to your post Chris Sloots!! This helped me so much…
thanks 2 years after… :p