28
Sep 11PHP DOM XML to Array
What is the fastest way to parse a XML string into a equivalent valid Array representation?
I have seen quite some efforts on different blogs and the comments on php.net in some of the functions suggest some valid approaches. The problem with most approaches though, i find, is the lack of xml testing before passing it to the function to transform the xml to array. When you want to make sure you have a valid XML string the PHP DOMDocument class and its sub classes provide everything for iteration through its childs, to saving string presentations to file and so on. On top DOM perfectly validates XML strings when passed into the loading methods of the class. Also i believe any approach using DOM rather then handling the XML string with regex or whatever should be much faster and safer to rely on.
More…