You are here

protected function SimpleXml::fetchNextRow in Migrate Plus 8.2

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

Retrieves the next row of data from the open source URL, populating currentItem.

Overrides DataParserPluginBase::fetchNextRow

File

src/Plugin/migrate_plus/data_parser/SimpleXml.php, line 56

Class

SimpleXml
Obtain XML data for migration using the SimpleXML API.

Namespace

Drupal\migrate_plus\Plugin\migrate_plus\data_parser

Code

protected function fetchNextRow() {
  $target_element = array_shift($this->matches);

  // If we've found the desired element, populate the currentItem and
  // currentId with its data.
  if ($target_element !== FALSE && !is_null($target_element)) {
    foreach ($this
      ->fieldSelectors() as $field_name => $xpath) {
      foreach ($target_element
        ->xpath($xpath) as $value) {
        $this->currentItem[$field_name][] = (string) $value;
      }
    }

    // Reduce single-value results to scalars.
    foreach ($this->currentItem as $field_name => $values) {
      if (count($values) == 1) {
        $this->currentItem[$field_name] = reset($values);
      }
    }
  }
}