You are here

protected function FeedsXPathParserDOMXPath::addDefaultNamespace in Feeds XPath Parser 6

Same name and namespace in other branches
  1. 7 FeedsXPathParserDOMXPath.inc \FeedsXPathParserDOMXPath::addDefaultNamespace()

Normalizes XPath queries, adding the default namespace.

Parameters

string $query: An XPath query string

1 call to FeedsXPathParserDOMXPath::addDefaultNamespace()
FeedsXPathParserDOMXPath::namespacedQuery in ./FeedsXPathParserDOMXPath.inc
Executes an XPath query with namespace support.

File

./FeedsXPathParserDOMXPath.inc, line 125
Provides a custom version of DOMXPath for use with feeds_xpathparser.

Class

FeedsXPathParserDOMXPath
Wraps DOMXPath providing enhanced debugging and special namespace handling.

Code

protected function addDefaultNamespace(&$query) {
  foreach ($this->namespaces as $prefix => $namespace) {
    if ($prefix === '') {
      $this
        ->registerNamespace('__default__', $namespace);

      // Replace all the elements without prefix by the default prefix.
      if (!isset($this->modifiedQueries[$query])) {
        $parser = new FeedsXPathParserQueryParser($query);
        $mod_query = $parser
          ->getQuery();
        $this->modifiedQueries[$query] = $mod_query;
        $query = $mod_query;
      }
      else {
        $query = $this->modifiedQueries[$query];
      }
    }
    else {
      $this
        ->registerNamespace($prefix, $namespace);
    }
  }
}