You are here

protected function FeedsExXml::validateExpression in Feeds extensible parsers 7

Same name and namespace in other branches
  1. 7.2 src/FeedsExXml.inc \FeedsExXml::validateExpression()

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 FeedsExBase::validateExpression

1 method overrides FeedsExXml::validateExpression()
FeedsExQueryPathXml::validateExpression in src/FeedsExQueryPathXml.inc
Validates an expression.

File

src/FeedsExXml.inc, line 177
Contains FeedsExXml.

Class

FeedsExXml
Parses XML documents with XPath.

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 = check_plain(trim($error->message));
    }
  }
  $this
    ->stopErrorHandling();
  return $message;
}