You are here

public function FeedsExXpathDomXpath::__construct in Feeds extensible parsers 7

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

Constructs a FeedsExXpathDomXpath object.

@todo Add an option to force a deep scan of namespaces.

Parameters

DOMDocument $document: The DOM document to parse.

File

src/FeedsExXml.inc, line 383
Contains FeedsExXml.

Class

FeedsExXpathDomXpath
Wraps DOMXPath simplifying usage.

Code

public function __construct(DOMDocument $document) {
  $this->xpath = new DOMXPath($document);

  // Find all namespaces.
  // Calling simplexml_import_dom() and SimpleXML::getNamespaces() is several
  // orders of magnitude faster than searching for the namespaces ourselves
  // using XPath.
  $simple = simplexml_import_dom($document);

  // An empty DOMDocument will make $simple NULL.
  if ($simple === NULL) {
    return;
  }
  foreach ($simple
    ->getNamespaces(TRUE) as $prefix => $namespace) {
    $this->xpath
      ->registerNamespace($prefix, $namespace);
  }
}