protected function FeedsExQueryPathXml::executeSourceExpression in Feeds extensible parsers 7
Same name and namespace in other branches
- 7.2 src/FeedsExQueryPathXml.inc \FeedsExQueryPathXml::executeSourceExpression()
Executes a single source expression.
Parameters
string $machine_name: The source machine name being executed.
string $expression: The expression to execute.
mixed $row: The row to execute on.
Return value
scalar|[]scalar Either a scalar, or a list of scalars. If null, the value will be ignored.
Overrides FeedsExXml::executeSourceExpression
File
- src/
FeedsExQueryPathXml.inc, line 51 - Contains FeedsExXml.
Class
- FeedsExQueryPathXml
- Parses XML documents with QueryPath.
Code
protected function executeSourceExpression($machine_name, $expression, $row) {
$result = new QueryPath($row, $expression, $this->queryPathOptions);
if ($result
->size() == 0) {
return;
}
$config = $this->config['sources'][$machine_name];
$return = array();
if (strlen($config['attribute'])) {
foreach ($result as $node) {
$return[] = $node
->attr($config['attribute']);
}
}
elseif (!empty($config['inner'])) {
foreach ($result as $node) {
$return[] = $node
->innerXML();
}
}
elseif (!empty($config['raw'])) {
foreach ($result as $node) {
$return[] = $this
->getRawValue($node);
}
}
else {
foreach ($result as $node) {
$return[] = $node
->text();
}
}
// Return a single value if there's only one value.
return count($return) === 1 ? reset($return) : $return;
}