You are here

protected static function FeedImport::getXpathValue in Feed Import 7

Same name and namespace in other branches
  1. 7.2 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 394
Feed import class for parsing and processing content

Class

FeedImport
@file Feed import class for parsing and processing content

Code

protected static function getXpathValue(&$item, $xpath) {
  $xpath = $item
    ->xpath($xpath);
  if (count($xpath) == 1) {
    $xpath = (array) reset($xpath);
    $xpath = isset($xpath[0]) ? $xpath[0] : reset($xpath);
  }
  else {
    foreach ($xpath as $key => &$x) {
      $x = (array) $x;
      $x = isset($x[0]) ? $x[0] : reset($x);
      if (empty($x)) {
        unset($xpath[$key], $x);
      }
    }
    if (count($xpath) == 1) {
      $xpath = reset($xpath);
    }
  }
  return $xpath;
}