Are there any recommended PHP functions or methods to decode HTML entities in XML data to avoid parsing errors?

When parsing XML data that contains HTML entities, such as & or <, it's important to decode these entities to avoid parsing errors. One recommended PHP function to achieve this is htmlspecialchars_decode(). This function will decode special HTML entities back to their original characters, ensuring that the XML data can be parsed correctly.

$xmlData = '<data><example>This is an & example</example></data>';
$decodedXmlData = htmlspecialchars_decode($xmlData);
$xml = simplexml_load_string($decodedXmlData);