I'm creating a XML object using PHP SimpleXMLElement
I have the full XML in $RAWResponse
, so I use
$oXMLResponse = new SimpleXMLElement($RAWresponse);
The XML I'm getting comes from a webservice. I detected the XML contains invalid chars, as '&' for instance.
There are a lot of posts about this issue but none works. I tried htmlentities() but this escapes every char, including the '<' and '>' opening and enclosing the XML Elements.
Finally I used this function :
$some_special_chars = array("&");
$replacement_chars = array("&");
$RAWresponse = str_replace($some_special_chars, $replacement_chars, $RAWresponse);
$oXMLResponse = new SimpleXMLElement($RAWresponse);
This works but it's a stupid solution, because it will break if I get any other special char. Is there a better solution? I cant understand why SimpleXMLElement breaks, it should only show a warning or something.