PHP’s SimpleXML
SimpleXML is a PHP library extension available from PHP 5+. It enables PHP to easily access the data and structure of an SML document.
Previously DOM and DOM XML were used by PHP developers to parse XML. DOM and DOM XML requires tens of commands to do what what SimpleXML can do in a couple of lines. Furthermore, unlike DOM and DOM XML, SimpleXML creates a PHP onject which requires many fewer commands to access, read and write to the XML document structure.
The SimpleXML document needs to be created before and, if manipulated, re-created before it can be parsed using PHP. An XML document can be created from scratch using a simple PHP string..
$string = ""; $xmObject = simplexml_load_string($string);
Alternatively, a pre-created XML document can be used to create an object from file…
$xmlObject = simplexml_load_file('test.xml');
Once the script has made its additions/changes to the object, it can be exported back as XML using the following command…
$xml = new SimpleXMLElement($xmlObject);
That’s pretty much it.
Related Posts
Post Information
Written on 5 October 2009 at 9.31 pm, by Keith Greer. "PHP’s SimpleXML" was posted in PHP with the tags data, PHP, XML . Comments Off
Social Networks: Facebook, Twitter, Google Bookmarks, del.icio.us, StumbleUpon, Digg, Reddit, Posterous.









