What are some common pitfalls when dealing with XML files in PHP, especially when it comes to encoding and special characters like é?

When dealing with XML files in PHP, one common pitfall is handling special characters like é. These characters need to be properly encoded to avoid parsing errors. One way to solve this issue is to use functions like htmlspecialchars() or utf8_encode() to properly encode the special characters before writing them to the XML file.

// Example of encoding special characters like é before writing to an XML file
$data = "<title>L'étranger</title>";
$encoded_data = htmlspecialchars($data, ENT_XML1);
// Write $encoded_data to the XML file