Bellow code showing “Object of class DOMDocument could not be converted to string”. How can i solve this issue.
$rs=$_SESSION['hotelavail_rs'];
// I have stored xml response in a session.
// xml response should be string type.
$str=(string)$rs;
$DOC = new DOMDocument();
$xml =new SimpleXMLElement($str);
$DOC->loadXML($str);
$Data = Parse($DOC->firstChild);
According to the docs for DOMDocument, you call
saveXML()to dump the XML to a string.I’m assuming the error is occurring on this line?
In which case you should change it to,
But since you seem to be loading it all back into a DOMDocument anyway, why not just do this?
If the error is occurring later (In the
Parsefunction for example) then a different solution will be required. It would be helpful to know the exact line on which the error is being thrown.Note: None of the above is tested, I’m just going on what the docs say.