Edit report at https://bugs.php.net/bug.php?id=48352&edit=1
ID: 48352 Comment by: troelskn at gmail dot com Reported by: php at xxlwebdesign dot de Summary: Method registerNodeClass does not work with DOMNodeList Status: Assigned Type: Feature/Change Request Package: DOM XML related Operating System: Gentoo PHP Version: 5.3CVS-2009-05-21 (snap) Assigned To: rrichards Block user comment: N Private report: N New Comment: @kroccamen While not that elegant, you can create a decorator to solve this issue. Here's a template to use: class MyDomElement extends DOMElement { function xpath($query) { return new DomNodeListDecorator($this->ownerDocument->getXpathSelector()- >query($query, $this)); } } class DomNodeListDecorator implements IteratorAggregate { protected $nodeList; function __construct($nodeList) { $this->nodeList = $nodeList; } function getIterator() { return $this->nodeList; } function __get($name) { if ($name == 'length') { return $this->nodeList->length; } throw new Exception("Undefined attribute {$name}"); } function item($index) { return $this->nodeList->item($index); } } Previous Comments: ------------------------------------------------------------------------ [2012-01-03 13:40:12] kroccamen at gmail dot com Iâd like to provide a valid use-case for this bug. I have created an extended DOMDocument that upon __construct also creates an XPath object, that way I can add methods to DOMElement to allow for DOMElement->xpath ('...') instead of using DOMXPath->query ('...', DOMNode). This makes the DOM more chainable and simpler to use without so many temporary variables. What I want to do is extend DOMNodeList so that one function call can apply to all nodes returned from an XPath query, e.g. DOMNode->xpath ('a')->addClass ('link'); Is anybody aware of any other work around that can be used to achieve this same effect? ------------------------------------------------------------------------ [2011-01-08 05:17:47] mat at homedvd dot ca Any movement on this? The method should probably be called registerNodeListClass ------------------------------------------------------------------------ [2010-02-15 02:45:10] mail at r-site dot net very helpfull, extending DOMNode's almost implies it, pls hurry, ty ------------------------------------------------------------------------ [2009-09-20 21:17:12] goetas at lignano dot it this would be really helpful! ------------------------------------------------------------------------ [2009-05-22 12:53:55] php at xxlwebdesign dot de This would be very nice! ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=48352 -- Edit this bug report at https://bugs.php.net/bug.php?id=48352&edit=1