What is the recommended method for reading XML files in PHP?

When working with XML files in PHP, the recommended method is to use the SimpleXML extension. SimpleXML provides an easy way to read, manipulate, and extract data from XML files. It allows you to access XML elements as if they were properties of an object, making the process more intuitive and straightforward.

$xmlString = file_get_contents('example.xml');
$xml = simplexml_load_string($xmlString);

foreach ($xml->book as $book) {
    echo $book->title . "<br>";
    echo $book->author . "<br>";
    echo $book->genre . "<br>";
    echo $book->price . "<br>";
    echo "<br>";
}