Reply to Re: [PHP] Extending Element class in a dom tree?

Your name:

Reply:


Posted by Christian Stocker on 05/01/05 01:51

Hi again

On 4/30/05, Christian Stocker <chregu@gmail.com> wrote:
> On 4/30/05, Erik Franzén <erik@nordicaudi.com> wrote:
> > The DOM implementation i PHP5 allows classes to be extended. Extending
> > the Document class is no problem, but how can I extend the Element class
> > and use it in a DOM tree?
> >
> > DOMDocument::createElement returns a DOMElement object which you cannot
> > extend.
> >
> > Could this be a solution?
> >
> > class MyElement extends DomElement {
> > function __construct($a_stTagName) {
> > //has to be called!
> > parent::__construct($a_stTagName);
> > }
> >
> > function myFunction() {
> > // do something
> > }
> > }
> >
> > $oDom = new DomDocument();
> > $oMyElement = new MyElement('mytag');
> >
> > $oMyElement = $oDom->importNode($oMyElement, true);
> > $oMyElement = $oDom->appendChild($oMyElement);
>
> Does not work, will never work, just forget about it ;)

Ok, that was not the really right answer ;) Of course it does work.
You can even do stuff on that element, if you use the variable, resp.
reference ($oMyElement) for doing this.

What doesn't work (and I referred to that) is getting this object
back from the DomDocument, so for example:
$oDom->documentElement will give you the DomElement back and not your
new MyElement.

Hope it's a little bit clearer now
chregu
>
> chregu
> >
> > Regards
> > /Erik
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
> --
> christian stocker | Bitflux GmbH | schoeneggstrasse 5 | ch-8004 zurich
> phone +41 1 240 56 70 | mobile +41 76 561 88 60 | fax +41 1 240 56 71
> http://www.bitflux.ch | chregu@bitflux.ch | gnupg-keyid 0x5CE1DECB
>


--
christian stocker | Bitflux GmbH | schoeneggstrasse 5 | ch-8004 zurich
phone +41 1 240 56 70 | mobile +41 76 561 88 60 | fax +41 1 240 56 71
http://www.bitflux.ch | chregu@bitflux.ch | gnupg-keyid 0x5CE1DECB

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация