trait XmlTrait in Migrate Plus 8.4
Same name and namespace in other branches
- 8.5 src/Plugin/migrate_plus/data_parser/XmlTrait.php \Drupal\migrate_plus\Plugin\migrate_plus\data_parser\XmlTrait
- 8.2 src/Plugin/migrate_plus/data_parser/XmlTrait.php \Drupal\migrate_plus\Plugin\migrate_plus\data_parser\XmlTrait
- 8.3 src/Plugin/migrate_plus/data_parser/XmlTrait.php \Drupal\migrate_plus\Plugin\migrate_plus\data_parser\XmlTrait
Common functionality for XML data parsers.
Hierarchy
- trait \Drupal\migrate_plus\Plugin\migrate_plus\data_parser\XmlTrait
File
- src/
Plugin/ migrate_plus/ data_parser/ XmlTrait.php, line 8
Namespace
Drupal\migrate_plus\Plugin\migrate_plus\data_parserView source
trait XmlTrait {
/**
* Registers the iterator's namespaces to a SimpleXMLElement.
*
* @param \SimpleXMLElement $xml
* The element to apply namespace registrations to.
*/
protected function registerNamespaces(\SimpleXMLElement $xml) {
if (isset($this->configuration['namespaces']) && 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\nLine: @libxmlerrorline\nColumn: @libxmlerrorcolumn\nFile: @libxmlerrorfile", [
'@libxmlerrorcodename' => $error_code_name,
'@libxmlerrorcode' => $error->code,
'@libxmlerrormessage' => trim($error->message),
'@libxmlerrorline' => $error->line,
'@libxmlerrorcolumn' => $error->column,
'@libxmlerrorfile' => $error->file ? $error->file : NULL,
]);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
XmlTrait:: |
public static | function | Parses a LibXMLError to a error message string. | |
XmlTrait:: |
protected | function | Registers the iterator's namespaces to a SimpleXMLElement. |