You are here

public function XMLMigration::applyXpath in Migrate 7.2

Same name and namespace in other branches
  1. 6.2 plugins/sources/xml.inc \XMLMigration::applyXpath()

Gets item from XML using the xpath.

Default implementation - straightforward xpath application

Parameters

stdClass $data_row: row containing items.

string $xpath: xpath used to find the item

Return value

SimpleXMLElement found element

1 call to XMLMigration::applyXpath()
XMLMigration::applyMappings in plugins/sources/xml.inc
A normal $data_row has all the input data as top-level fields - in this case, however, the data is embedded within a SimpleXMLElement object in $data_row->xml. Explode that out to the normal form, and pass on to the normal implementation.

File

plugins/sources/xml.inc, line 399
Support for migration from XML sources.

Class

XMLMigration
Migrations using XML sources should extend this class instead of Migration.

Code

public function applyXpath($data_row, $xpath) {
  $result = $data_row->xml
    ->xpath($xpath);
  if ($result) {
    if (count($result) > 1) {
      $return = array();
      foreach ($result as $record) {
        $return[] = (string) $record;
      }
      return $return;
    }
    else {
      return (string) $result[0];
    }
  }
  else {
    return NULL;
  }
}