How to check if a string is a valid XML string

function isValidXMLString($content) { 

    // removing empty spaces from the left and right sides 
    $content = trim($content); 

    // reject processing if content is empty OR if content starts as HTML document 
    if (empty($content) || stripos($content, '<!DOCTYPE html>') !== false) return false; 

    // turn on lib function for catching errors 
    libxml_use_internal_errors(true); 

    // transforming a string into SimpleXML 
    simplexml_load_string($content); 

    // collect any errors appears 
    $errors = libxml_get_errors(); 

    // clean those errors from the buffer 
    libxml_clear_errors(); 

    // so, it was transformed without issues or with? 
    return empty($errors); 
}

List of possible results regarding the input value:

// true 
var_dump(isValidXml('<?xml version="1.0" standalone="yes"?><root></root>')); 

// false 
var_dump(isValidXml(null)); 

// false 
var_dump(isValidXml(1)); 

// false 
var_dump(isValidXml(false)); 

// false 
var_dump(isValidXml('asdasds')); 

// false 
var_dump(isValidXml('<!DOCTYPE html><html><body></body></html>'));