You are here

public function Xml::getAncestorElements in Migrate Plus 8.5

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

Gets an ancestor SimpleXMLElement, if the element name was registered.

Gets the SimpleXMLElement some number of levels above the iterator having the given name, but only for element names that this Xml data parser was told to retain for future reference through the constructor's $parent_elements_of_interest.

Parameters

int $levels_up: The number of levels back towards the root of the DOM tree to ascend before searching for the named element.

string $name: The name of the desired element.

Return value

\SimpleXMLElement|false The element matching the level and name requirements, or false if it is not present or was not retained.

1 call to Xml::getAncestorElements()
Xml::fetchNextRow in src/Plugin/migrate_plus/data_parser/Xml.php
Retrieves the next row of data. populating currentItem.

File

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

Class

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

Namespace

Drupal\migrate_plus\Plugin\migrate_plus\data_parser

Code

public function getAncestorElements($levels_up, $name) {
  if ($levels_up > 0) {
    $levels_up *= -1;
  }
  $ancestor_depth = $this->reader->depth + $levels_up + 1;
  if ($ancestor_depth < 0) {
    return FALSE;
  }
  if (array_key_exists($ancestor_depth, $this->parentXpathCache) && array_key_exists($name, $this->parentXpathCache[$ancestor_depth])) {
    return $this->parentXpathCache[$ancestor_depth][$name];
  }
  else {
    return FALSE;
  }
}