You are here

public function Xml::__construct in Migrate Plus 8.4

Same name and namespace in other branches
  1. 8.5 src/Plugin/migrate_plus/data_parser/Xml.php \Drupal\migrate_plus\Plugin\migrate_plus\data_parser\Xml::__construct()
  2. 8.2 src/Plugin/migrate_plus/data_parser/Xml.php \Drupal\migrate_plus\Plugin\migrate_plus\data_parser\Xml::__construct()
  3. 8.3 src/Plugin/migrate_plus/data_parser/Xml.php \Drupal\migrate_plus\Plugin\migrate_plus\data_parser\Xml::__construct()

Constructs a \Drupal\Component\Plugin\PluginBase object.

Parameters

array $configuration: A configuration array containing information about the plugin instance.

string $plugin_id: The plugin_id for the plugin instance.

mixed $plugin_definition: The plugin implementation definition.

Overrides DataParserPluginBase::__construct

File

src/Plugin/migrate_plus/data_parser/Xml.php, line 92

Class

Xml
Obtain XML data for migration using the XMLReader pull parser.

Namespace

Drupal\migrate_plus\Plugin\migrate_plus\data_parser

Code

public function __construct(array $configuration, $plugin_id, $plugin_definition) {
  parent::__construct($configuration, $plugin_id, $plugin_definition);
  $this->reader = new \XMLReader();

  // Suppress errors during parsing, so we can pick them up after.
  libxml_use_internal_errors(TRUE);

  // Parse the element query. First capture group is the element path, second
  // (if present) is the attribute.
  preg_match_all('|^/([^\\[]+)\\[?(.*?)]?$|', $configuration['item_selector'], $matches);
  $element_path = $matches[1][0];
  $this->elementsToMatch = explode('/', $element_path);
  $predicate = $matches[2][0];
  if ($predicate) {
    $this->xpathPredicate = $predicate;
  }

  // If the element path contains any colons, it must be specifying
  // namespaces, so we need to compare using the prefixed element
  // name in next().
  if (strpos($element_path, ':')) {
    $this->prefixedName = TRUE;
  }
  foreach ($this
    ->fieldSelectors() as $field_name => $xpath) {
    $prefix = substr($xpath, 0, 3);
    if ($prefix === '../') {
      $this->parentElementsOfInterest[] = str_replace('../', '', $xpath);
    }
    elseif ($prefix === '..\\') {
      $this->parentElementsOfInterest[] = str_replace('..\\', '', $xpath);
    }
  }
}