public function FeedImportSimpleXPathReader::map in Feed Import 7.3
Returns a value mapped from obj by path.
Parameters
mixed $obj Variable to search:
mixed $path Path to value:
Return value
mixed Mapped value
Overrides FeedImportReader::map
File
- feed_import_base/
inc/ feed_import_abstract.inc, line 138 - This file contains abstract classes and interfaces for feed import.
Class
- FeedImportSimpleXPathReader
- This class is a helper for xpath readers using SimpleXMLElement.
Code
public function map(&$item, &$xpath) {
// Get values and handle xpath exceptions.
try {
$values = $item
->xpath($xpath);
} catch (Exception $e) {
return NULL;
}
// Xpath gave no values return null.
if (!$values) {
return NULL;
}
// Get the number of values.
$count = count($values);
$i = -1;
while (++$i < $count) {
// Get each value.
$values[$i] = (string) $values[$i][0];
}
// Return values.
return $count == 1 ? $values[0] : $values;
}