You are here

protected function FeedsXPathParserBase::parseSourceElement in Feeds XPath Parser 6

Same name and namespace in other branches
  1. 7 FeedsXPathParserBase.inc \FeedsXPathParserBase::parseSourceElement()

Parses one item from the context array.

Parameters

$item: A SimpleXMLElement from the context array.

$query: An XPath query.

$source: The name of the source for this query.

Return value

array An array containing the results of the query.

1 call to FeedsXPathParserBase::parseSourceElement()
FeedsXPathParserBase::parse in ./FeedsXPathParserBase.inc
Implements FeedsParser::parse().

File

./FeedsXPathParserBase.inc, line 101
Provides the abstract base class for FeedsXPathParserHTML and FeedsXPathParserXML.

Class

FeedsXPathParserBase
Base class for the HTML and XML parsers.

Code

protected function parseSourceElement($query, $context, $source) {
  if (empty($query)) {
    return;
  }
  $node_list = $this->xpath
    ->namespacedQuery($query, $context, $source);

  /**
   * Iterate through the results of the XPath query.  If this source is
   * configured to return raw xml, make it so.
   */
  if ($node_list instanceof DOMNodeList) {
    $results = array();
    if (in_array($source, $this->rawXML)) {
      foreach ($node_list as $node) {
        $results[] = $this
          ->getRaw($node);
      }
    }
    else {
      foreach ($node_list as $node) {
        $results[] = $node->nodeValue;
      }
    }

    // Return single result if so.
    if (count($results) === 1) {
      return $results[0];
    }
    elseif (empty($results)) {
      return;
    }
    else {
      return $results;
    }
  }
  else {
    return $node_list;
  }
}