How can SimpleXML be used effectively to parse and manipulate XML data in PHP?

SimpleXML can be effectively used in PHP to parse and manipulate XML data by loading the XML string or file into a SimpleXMLElement object. This object can then be navigated like a typical PHP object using properties and methods, making it easy to access and modify the XML data. SimpleXML provides a simple and intuitive way to work with XML data without the need for complex parsing functions.

// Load XML file
$xml = simplexml_load_file('data.xml');

// Access and manipulate XML data
foreach ($xml->book as $book) {
    echo $book->title . "<br>";
    $book->author = "New Author";
}

// Save changes back to file
$xml->asXML('data.xml');