Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' of git://git.zendframework.com/zf
Browse files Browse the repository at this point in the history
  • Loading branch information
Shahar Evron committed Jul 25, 2010
4 parents ff81391 + cfbc839 + 49e4d7c + 21cca29 commit f0671be
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Css2Xpath.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ protected static function _tokenize($expression)
// arbitrary attribute strict equality
$expression = preg_replace_callback(
'|\[([a-z0-9_-]+)=[\'"]([^\'"]+)[\'"]\]|i',
function($matches) {
function ($matches) {
return '[@' . strtolower($matches[1]) . "='" . $matches[2] . "']";
},
$expression
Expand Down
20 changes: 20 additions & 0 deletions src/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ class Query
*/
protected $_docType;

/**
* XPath namespaces
* @var array
*/
protected $_xpathNamespaces = array();

/**
* Constructor
*
Expand Down Expand Up @@ -215,6 +221,17 @@ public function queryXpath($xpathQuery, $query = null)
return new NodeList($query, $xpathQuery, $domDoc, $nodeList);
}

/**
* Register XPath namespaces
*
* @param array $xpathNamespaces
* @return void
*/
public function registerXpathNamespaces($xpathNamespaces)
{
$this->_xpathNamespaces = $xpathNamespaces;
}

/**
* Prepare node list
*
Expand All @@ -225,6 +242,9 @@ public function queryXpath($xpathQuery, $query = null)
protected function _getNodeList($document, $xpathQuery)
{
$xpath = new \DOMXPath($document);
foreach ($this->_xpathNamespaces as $prefix => $namespaceUri) {
$xpath->registerNamespace($prefix, $namespaceUri);
}
$xpathQuery = (string) $xpathQuery;
return $xpath->query($xpathQuery);
}
Expand Down

0 comments on commit f0671be

Please sign in to comment.