22 if (!is_string(
$xml) || trim(
$xml) ===
'') {
23 throw InvalidArgumentException::invalidType(
'non-empty string',
$xml);
26 $entityLoader = libxml_disable_entity_loader(
true);
27 $internalErrors = libxml_use_internal_errors(
true);
28 libxml_clear_errors();
30 $domDocument = self::create();
31 $options = LIBXML_DTDLOAD | LIBXML_DTDATTR | LIBXML_NONET;
32 if (defined(LIBXML_COMPACT)) {
38 libxml_use_internal_errors($internalErrors);
39 libxml_disable_entity_loader($entityLoader);
42 $error = libxml_get_last_error();
43 libxml_clear_errors();
48 libxml_clear_errors();
50 foreach ($domDocument->childNodes as $child) {
51 if ($child->nodeType === XML_DOCUMENT_TYPE_NODE) {
53 'Dangerous XML detected, DOCTYPE nodes are not allowed in the XML body' 68 if (!is_string($file)) {
69 throw InvalidArgumentException::invalidType(
'string', $file);
72 if (!is_file($file)) {
76 if (!is_readable($file)) {
82 $xml = file_get_contents($file);
85 'Contents of readable file "%s" could not be gotten',
90 if (trim(
$xml) ===
'') {
91 throw new RuntimeException(sprintf(
'File "%s" does not have content', $file));
94 return static::fromString(
$xml);
102 return new \DOMDocument();