I am coding a PHP rest Service. I am sending xml string from client and service parse the xml with SimpleXmlElement. If I send "hello world" instead of xml string, the below piece of code produce warnings in the browser. how can I check the input to be valid xml string not some sentence.
try
{
xmlobj = new SimpleXMLElement($xml_post);
}
catch(Exception $e)
{
$dat = $e->getMessage();
return $dat;
}
The warning is something like this
SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : Start tag expected, '<' not found
I want to validate the input before calling SimpleXMLElement class construtor.