You are here

protected function FeedsXPathParserBase::parseSourceElement in Feeds XPath Parser 7

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

Parses one item from the context array.

Parameters

string $query: An XPath query.

DOMNode $context: The current context DOMNode .

string $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 153
Provides the 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;
  }
}