What are the advantages of using DOMDocument over SimpleXMLElement for XML manipulation in PHP?

When manipulating XML in PHP, using DOMDocument provides more flexibility and control compared to SimpleXMLElement. DOMDocument allows for easier navigation of the XML structure, modification of elements and attributes, and handling of namespaces. Additionally, DOMDocument provides methods for creating, loading, and saving XML documents, making it a more versatile choice for complex XML manipulation tasks.

// Example of using DOMDocument for XML manipulation
$xml = '<root><element>value</element></root>';

$dom = new DOMDocument();
$dom->loadXML($xml);

$element = $dom->getElementsByTagName('element')->item(0);
$element->nodeValue = 'new value';

$newXml = $dom->saveXML();
echo $newXml;