You are here

protected function XmlParser::validateExpression in Feeds extensible parsers 8

Validates an expression.

Parameters

string &$expression: The expression to validate.

Return value

string|null Return the error string, or null if validation was passed.

Overrides ParserBase::validateExpression

1 method overrides XmlParser::validateExpression()
QueryPathXmlParser::validateExpression in src/Feeds/Parser/QueryPathXmlParser.php
Validates an expression.

File

src/Feeds/Parser/XmlParser.php, line 245

Class

XmlParser
Defines a XML parser using XPath.

Namespace

Drupal\feeds_ex\Feeds\Parser

Code

protected function validateExpression(&$expression) {
  $expression = trim($expression);
  $message = NULL;
  if (!$expression) {
    return $message;
  }
  $this
    ->startErrorHandling();
  $xml = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<items></items>");
  $xml
    ->xpath($expression);
  if ($error = libxml_get_last_error()) {

    // Our variable substitution options can cause syntax errors, check if
    // we're doing that.
    if ($error->code == 1207 && strpos($expression, '$') !== FALSE) {

      // Do nothing.
    }
    elseif ($error->code != 1219) {
      $message = Html::escape(trim($error->message));
    }
  }
  $this
    ->stopErrorHandling();
  return $message;
}