public static function FeedImport::getXpathValue in Feed Import 7.2
Same name and namespace in other branches
- 7 feed_import.inc.php \FeedImport::getXpathValue()
Get value with xpath
Parameters
SimpleXMLElement &$item: Simplexmlobject to apply xpath on
string $xpath: Xpath to value
Return value
mixed A string or array of strings as a result of xpath function
1 call to FeedImport::getXpathValue()
- FeedImport::createEntity in ./
feed_import.inc.php - Create Entity object
File
- ./
feed_import.inc.php, line 410 - Feed import class for parsing and processing content.
Class
- FeedImport
- @file Feed import class for parsing and processing content.
Code
public static function getXpathValue(&$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 value or an array of values.
return $count == 1 ? $values[0] : $values;
}