protected function ParserBase::parseSourceElement in Feeds XPath Parser 8
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 ParserBase::parseSourceElement()
- ParserBase::parse in lib/
Drupal/ feeds_xpathparser/ ParserBase.php
File
- lib/
Drupal/ feeds_xpathparser/ ParserBase.php, line 159 - Contains \Drupal\feeds_xpathparser\ParserBase.
Class
- ParserBase
- Base class for the HTML and XML parsers.
Namespace
Drupal\feeds_xpathparserCode
protected function parseSourceElement($query, $context, $source) {
if (empty($query)) {
return;
}
$node_list = $this->xpath
->namespacedQuery($query, $source, $context);
// 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;
}
}