XmlParserTrait.php in Feeds 8.3
File
src/Component/XmlParserTrait.php
View source
<?php
namespace Drupal\feeds\Component;
trait XmlParserTrait {
protected static $_elementRegex = '[:A-Z_a-z\\xC0-\\xD6\\xD8-\\xF6\\xF8-\\x{2FF}\\x{370}-\\x{37D}\\x{37F}-\\x{1FFF}\\x{200C}-\\x{200D}\\x{2070}-\\x{218F}\\x{2C00}-\\x{2FEF}\\x{3001}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFFD}\\x{10000}-\\x{EFFFF}][:A-Z_a-z\\xC0-\\xD6\\xD8-\\xF6\\xF8-\\x{2FF}\\x{370}-\\x{37D}\\x{37F}-\\x{1FFF}\\x{200C}-\\x{200D}\\x{2070}-\\x{218F}\\x{2C00}-\\x{2FEF}\\x{3001}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFFD}\\x{10000}-\\x{EFFFF}\\.\\-0-9\\xB7\\x{0300}-\\x{036F}\\x{203F}-\\x{2040}]*';
protected static $_useError;
protected static $_entityLoader;
protected static $_errors = [];
protected static function getDomDocument($source, $options = 0) {
static::startXmlErrorHandling();
$document = new \DOMDocument('1.0', 'utf-8');
$document->strictErrorChecking = FALSE;
$document->resolveExternals = FALSE;
$document->substituteEntities = FALSE;
$document->recover = TRUE;
$options = $options | LIBXML_NOENT | LIBXML_NONET | defined('LIBXML_COMPACT') ? LIBXML_COMPACT : 0;
$options = $options | defined('LIBXML_PARSEHUGE') ? LIBXML_PARSEHUGE : 0;
$document
->loadXML($source, $options);
static::stopXmlErrorHandling();
return $document;
}
protected static function startXmlErrorHandling() {
static::$_useError = libxml_use_internal_errors(TRUE);
static::$_entityLoader = libxml_disable_entity_loader(TRUE);
libxml_clear_errors();
}
protected static function stopXmlErrorHandling() {
foreach (libxml_get_errors() as $error) {
static::$_errors[$error->level][] = [
'message' => trim($error->message),
'line' => $error->line,
'code' => $error->code,
];
}
libxml_clear_errors();
libxml_use_internal_errors(static::$_useError);
libxml_disable_entity_loader(static::$_entityLoader);
}
protected static function getXmlErrors() {
return static::$_errors;
}
protected static function removeDefaultNamespaces($xml) {
return preg_replace('/(<' . static::$_elementRegex . '[^>]*)\\s+xmlns\\s*=\\s*("|\').*?(\\2)([^>]*>)/u', '$1$4', $xml);
}
}