You are here

public function XMLMigration::applyXpath in Migrate 6.2

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

Default implementation - straightforward xpath application

Parameters

$data_row:

$xpath:

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 274
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;
  }
}