Here is my code:
\');
$pro         
        Sorry for reviving an old question, but there is another solution to this.. Assuming the following code causes the "unterminated entity reference" error:
$xml->addChild($key,$value); 
@Joel-Davey's solution works very well:
$xml->addChild($key,htmlspecialchars($value)); 
But you can also do the following if, for some reason, you don't want to use the above htmlspecialchars function (basically, you split the one step into two steps):
$xml->addChild($key); 
$xml->$key=$value; 
i have no idea which one will execute faster; i doubt it'd make much of a difference, but, this works, and i thought it should be mentioned
PS: i know it works because i'm using it on a personal project