public static function isValidXmlFragment($xml, $doc = null)
    {
        if ($doc == null) {
            $doc = new DOMDocument("1.0", "ISO-8859-1");
        }

        $fragment = $doc->createDocumentFragment();
        @$fragment->appendXML($xml);
        $node = @$doc->appendChild($fragment);

        return $node !== false;
    }