Skip to content

Instantly share code, notes, and snippets.

@hakre
Created July 14, 2015 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hakre/0d83da87ad5781e9bc97 to your computer and use it in GitHub Desktop.
Save hakre/0d83da87ad5781e9bc97 to your computer and use it in GitHub Desktop.
DOMBLAZE II XMLNS
<?php
/**
* DOMBLAZE II is just with XMLNS support
*
* @link http://stackoverflow.com/a/26327033/367456
*/
/* DOMBLAZE II XMLNS */ $doc->registerNodeClass("DOMElement", "DOMBLAZE");
class DOMBLAZE extends DOMElement
{
/**
* @param $expression
*
* @return DomNode|DOMXPath|IteratorIterator|String|DOMElement[]
*/
public function __invoke($expression = null)
{
return $this->xpath($expression);
}
/**
* @param string $expression [optional]
*
* @return IteratorIterator|DOMXPath|DomNode|String|DOMElement[]
*/
function xpath($expression = null)
{
isset($this->ownerDocument->xpath) || $this->ownerDocument->xpath = new DOMXPath($this->ownerDocument);
if ($expression === null) {
return $this->ownerDocument->xpath;
}
$result = $this->ownerDocument->xpath->evaluate($expression, $this);
return ($result instanceof DOMNodeList) ? new IteratorIterator($result) : $result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment