diff -u b/src/Plugin/migrate_plus/data_parser/SimpleXml.php b/src/Plugin/migrate_plus/data_parser/SimpleXml.php --- b/src/Plugin/migrate_plus/data_parser/SimpleXml.php +++ b/src/Plugin/migrate_plus/data_parser/SimpleXml.php @@ -6,7 +6,7 @@ use Drupal\migrate_plus\DataParserPluginBase; /** - * Obtain XML data for migration. + * Obtain XML data for migration using the SimpleXML API. * * @DataParser( * id = "simple_xml", @@ -15,6 +15,8 @@ */ class SimpleXml extends DataParserPluginBase { + use XmlTrait; + /** * Array of matches from item_selector. * @@ -73,57 +75,2 @@ - /** - * Registers the iterator's namespaces to a SimpleXMLElement. - * - * @param \SimpleXMLElement $xml - * The element to apply namespace registrations to. - */ - protected function registerNamespaces(\SimpleXMLElement $xml) { - if (is_array($this->configuration['namespaces'])) { - foreach ($this->configuration['namespaces'] as $prefix => $ns) { - $xml->registerXPathNamespace($prefix, $ns); - } - } - } - - /** - * Parses a LibXMLError to a error message string. - * - * @param \LibXMLError $error - * Error thrown by the XML. - * - * @return string - * Error message - */ - public static function parseLibXmlError(\LibXMLError $error) { - $error_code_name = 'Unknown Error'; - switch ($error->level) { - case LIBXML_ERR_WARNING: - $error_code_name = t('Warning'); - break; - - case LIBXML_ERR_ERROR: - $error_code_name = t('Error'); - break; - - case LIBXML_ERR_FATAL: - $error_code_name = t('Fatal Error'); - break; - } - - return t( - "@libxmlerrorcodename @libxmlerrorcode: @libxmlerrormessage\n" . - "Line: @libxmlerrorline\n" . - "Column: @libxmlerrorcolumn\n" . - "File: @libxmlerrorfile", - [ - '@libxmlerrorcodename' => $error_code_name, - '@libxmlerrorcode' => $error->code, - '@libxmlerrormessage' => trim($error->message), - '@libxmlerrorline' => $error->line, - '@libxmlerrorcolumn' => $error->column, - '@libxmlerrorfile' => (($error->file)) ? $error->file : NULL, - ] - ); - } - } diff -u b/src/Plugin/migrate_plus/data_parser/Xml.php b/src/Plugin/migrate_plus/data_parser/Xml.php --- b/src/Plugin/migrate_plus/data_parser/Xml.php +++ b/src/Plugin/migrate_plus/data_parser/Xml.php @@ -2,19 +2,20 @@ namespace Drupal\migrate_plus\Plugin\migrate_plus\data_parser; -use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\migrate\MigrateException; use Drupal\migrate_plus\DataParserPluginBase; /** - * Obtain XML data for migration. + * Obtain XML data for migration using the XMLReader pull parser. * * @DataParser( * id = "xml", * title = @Translation("XML") * ) */ -class Xml extends SimpleXml implements ContainerFactoryPluginInterface { +class Xml extends DataParserPluginBase { + + use XmlTrait; /** * The XMLReader we are encapsulating. only in patch2: unchanged: --- /dev/null +++ b/src/Plugin/migrate_plus/data_parser/XmlTrait.php @@ -0,0 +1,65 @@ +configuration['namespaces'])) { + foreach ($this->configuration['namespaces'] as $prefix => $ns) { + $xml->registerXPathNamespace($prefix, $ns); + } + } + } + + /** + * Parses a LibXMLError to a error message string. + * + * @param \LibXMLError $error + * Error thrown by the XML. + * + * @return string + * Error message + */ + public static function parseLibXmlError(\LibXMLError $error) { + $error_code_name = 'Unknown Error'; + switch ($error->level) { + case LIBXML_ERR_WARNING: + $error_code_name = t('Warning'); + break; + + case LIBXML_ERR_ERROR: + $error_code_name = t('Error'); + break; + + case LIBXML_ERR_FATAL: + $error_code_name = t('Fatal Error'); + break; + } + + return t( + "@libxmlerrorcodename @libxmlerrorcode: @libxmlerrormessage\n" . + "Line: @libxmlerrorline\n" . + "Column: @libxmlerrorcolumn\n" . + "File: @libxmlerrorfile", + [ + '@libxmlerrorcodename' => $error_code_name, + '@libxmlerrorcode' => $error->code, + '@libxmlerrormessage' => trim($error->message), + '@libxmlerrorline' => $error->line, + '@libxmlerrorcolumn' => $error->column, + '@libxmlerrorfile' => (($error->file)) ? $error->file : NULL, + ] + ); + } + +}