Saturday, June 09, 2007
I just came across a this useful article over at DevShed on PHP 5's simpleXML functions. PHP in my opinion is really lacking in XML support which is weird, but having used coldfusion with xml and seeing how easy it is and I presume it is just as easy in .NET I was suprised at just how difficult it is in PHP. Until recently I have been using PHP4 for almost every project, even though PHP4 is now 7 years old mainly because a lot of hosting providers haven't upgraded but with PHP5 turning 3 I can't see any real reason for this, especially when it is open source?!Anyway, ranting aside the SimpleXML functions certainly take some of the pain out of parsing an XML document and this article has a nice XMLParser class for you to use. One thing to note, if you are using their example:
foreach($nodes as $node){
echo 'Postal address: '.$node->address.'
';
}
and want to know how to save the addresses to an array to use later on I found that you have to cast the $node->address as a string like this:
$addresses = array();
foreach($nodes as $node){
echo 'Postal address: '.(string) $node->address.'
';
}
hope this helps.
Jon 2:08 PM Permalink
