PHP5 provides easy functions to access and manipulate xml.
SimpleXML and DOM.
SimpleXML sacrifices so many functionalities for simplicity.
This is a trade-off for the power and flexibility it provides.
You cannot remove and manipulate elements using simplexml directly.
But we can do the same using DOM. Also we can export simplexml objects to dom
and do the required modification. This is a pretty good feature.
Loading and Saving XML Documents:
There are two ways for loading xml documents.
First by loading from a file and second from string.
From File :
// PHP Script
<?php
$dom = new DOMDocument();
$dom->load("library.xml");
echo $dom->saveXML();
?>
//XML - Create a file library.xml and paste the following xml to it.
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
From string
// PHP Script
<?php
$xml = <<<XML
<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
XML;
?>