note 76838 added to ref.dom
| From: | FrancoisHill at osu1 dot php dot net | Date: | Wed, 01 Aug 2007 18:21:05 +0000 |
| Subject: | note 76838 added to ref.dom | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-129109@lists.php.net to get a copy of this message | ||
In response to lutfi at smartconsultant dot us :
(see my post on
http://fr2.php.net/manual/en/
function.dom-domdocument-getelementsbytagname.php
)
Use this class I wrote:
class XPathableNode extends DOMNode
{
protected $Node;
protected $DOMDocument_from_node;
protected $DOMXpath_for_node;
public function __construct(/* DOMNode */ $node)
{
$this->Node=$node;
$this->DOMDocument_from_node=new
DomDocument();
$domNode=$this->DOMDocument_from_node
->importNode($this->Node, true);
$this->DOMDocument_from_node
->appendChild($domNode);
$this->DomXpath_for_node =
new Domxpath($this->
DOMDocument_from_node);
}
public function convertHTML()
{ return $this->DOMDocument_from_node
->saveHTML();
}
public /*DomNodeList*/ function applyXpath($xpath)
{ return $this->DomXpath_for_node
->query($xpath);
}
}
(sorry for the display... What a terrible hinderance on the
part of php.net !)
Then :
Make a new XPathableNode out of your parent node.
You may then retrieve a DOMNodeList from it by applying a
xpath (thus being able to specify the depth and name of
elements you want).
Has got me around some (of the many) DOM awkwardnesses a few times.
;o)
----
Server IP: 217.174.196.197
Probable Submitter: 194.153.88.6
----
Manual Page -- http://www.php.net/manual/en/ref.dom.php
Edit -- https://master.php.net/note/edit/76838
Del: integrated -- https://master.php.net/note/delete/76838/integrated
Del: useless -- https://master.php.net/note/delete/76838/useless
Del: bad code -- https://master.php.net/note/delete/76838/bad+code
Del: spam -- https://master.php.net/note/delete/76838/spam
Del: non-english -- https://master.php.net/note/delete/76838/non-english
Del: in docs -- https://master.php.net/note/delete/76838/in+docs
Del: other reasons-- https://master.php.net/note/delete/76838
Reject -- https://master.php.net/note/reject/76838
Search -- https://master.php.net/manage/user-notes.php