code: static function checkCreateXml($str)
      {
          $dom = new DOMDocument;
          $dom->encoding = 'utf-8';
  
          $textNode = $dom->createTextNode($str);
  
          if (!$textNode) {
              return false;
          }
  
          $element = $dom->createElement('element')
              ->appendChild($textNode);
  
          if (!$element) {
              return false;
          }
  
          @$dom->appendChild($element);
  
          $xml = $dom->saveXML();
  
          return !empty($xml);
      }
docs: Check if xml was created successfully with $str
  @param $str string
  @return boolean