core error

SimpleXML in PHP

Posted on: 15/08/2011


SimpleXML is a PHP extension (enabled by default after PHP 5.1.2) which provides a simple toolset to convert an XML document into an object so it can be easily used by a PHP application


Before PHP5 handling XML documents was quite painful.  With SimpleXML you just need to create one SimpleXMLElement and from that moment on you can use the XML document as it was a regular object where each node is an attribute containing other attributes/nodes.


$xmlstr = <<<XML
<?xml version='1.0' standalone='yes'?>
<title>Back to the Future</title>
<name>Dr. Brown</name>
<actor>Christopher Lloyd</actor>
<rating type="stars">5</rating>

$xml = new SimpleXMLElement($xmlstr);
echo $xml->movie[0]->plot;

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s


  • None
  • Justin Cooney: Great comic, this made me laugh!
  • Justin Cooney: Interesting, I didn't know about the Google App Engine, I'm glad I found your article on it!


%d bloggers like this: