Page 1 of 1

XML to PHP array - here's more info

Posted: Tue Jan 13, 2004 8:36 am
by patrikG
Yes, there are commercial solutions, and yes, in PHP 5 the DOM will be nice & cosy with XML, but for now extracting data from XML with PHP is a bit of a pain - a bit.

There is a nice and illuminating article on this which explains it quite clearly - so if you need to do this stuff (I am not talking about generating XML with PHP, but parsing), maybe you find this helpful as well:

http://www.devarticles.com/c/a/PHP/Conv ... Structure/

Posted: Tue Jan 13, 2004 3:07 pm
by scorphus
Many thanks, patrickG. Very nice article.

Posted: Wed Jan 21, 2004 7:07 am
by patrikG
Hmm...there is actually a PHP function that parses an xml-file into an array - although a darstardly one which doesn't mirror the parent-child relationships of the xml-document.
[php_man]xml_parse_into_struct[/php_man]

It's not beautiful and after playing around with it for a couple of days I wouldn't recommend it. Rather use one of the functions provided in the user-notes to generate a proper multidimensional array - provided you don't have server-access and can't install expat (PHP's xpath library).