DOMElement doesn"t seem to extend DOMNode...?

DOMElement doesn"t seem to extend DOMNode...?

am 13.11.2007 04:25:14 von Sean Quinn

I realize what the documentation says, but when creating both a new
DOMElement object, or extending the DOMElement object I don't have
access to any DOMNode methods in PHP 5.2.0.
e.g.

class HtmlElement extends DOMElement
{
...
}

$htmlElement = new HtmlElement();
$htmlElement->appendChild(...);

Will not work because the method is supposedly undefined. In
addition:

$domEl = new DOMElement();
$domEl->appendChild(...);

.... doesn't seem to work either. I've looked through several sources
online and offline which all seem to indicate that calls to DOMNode
methods should be working, but they aren't for me. Am I going crazy?
Am I doing something wrong? Anyone please help! Thanks!

Re: DOMElement doesn"t seem to extend DOMNode...?

am 13.11.2007 07:16:26 von taps128

Sean Quinn wrote:
> I realize what the documentation says, but when creating both a new
> DOMElement object, or extending the DOMElement object I don't have
> access to any DOMNode methods in PHP 5.2.0.
> e.g.
>
> class HtmlElement extends DOMElement
> {
> ...
> }
>
> $htmlElement = new HtmlElement();
> $htmlElement->appendChild(...);
>
> Will not work because the method is supposedly undefined. In
> addition:
>
> $domEl = new DOMElement();
> $domEl->appendChild(...);
>
> ... doesn't seem to work either. I've looked through several sources
> online and offline which all seem to indicate that calls to DOMNode
> methods should be working, but they aren't for me. Am I going crazy?
> Am I doing something wrong? Anyone please help! Thanks!
>
You can't append an child to an initialized DOMElement until it's
appended to the DOMDocument.
$dom=new DOMDocument();
$ele=new DOMElement('p');
$dom->appendChild($ele);
$ele2=new DOMELement('br');
$ele->appendChild($ele2);

Re: DOMElement doesn"t seem to extend DOMNode...?

am 13.11.2007 14:35:22 von Sean Quinn

On Nov 13, 1:16 am, taps128 wrote:
> Sean Quinn wrote:
> > I realize what the documentation says, but when creating both a new
> > DOMElement object, or extending the DOMElement object I don't have
> > access to any DOMNode methods in PHP 5.2.0.
> > e.g.
>
> > class HtmlElement extends DOMElement
> > {
> > ...
> > }
>
> > $htmlElement = new HtmlElement();
> > $htmlElement->appendChild(...);
>
> > Will not work because the method is supposedly undefined. In
> > addition:
>
> > $domEl = new DOMElement();
> > $domEl->appendChild(...);
>
> > ... doesn't seem to work either. I've looked through several sources
> > online and offline which all seem to indicate that calls to DOMNode
> > methods should be working, but they aren't for me. Am I going crazy?
> > Am I doing something wrong? Anyone please help! Thanks!
>
> You can't append an child to an initialized DOMElement until it's
> appended to the DOMDocument.
> $dom=new DOMDocument();
> $ele=new DOMElement('p');
> $dom->appendChild($ele);
> $ele2=new DOMELement('br');
> $ele->appendChild($ele2);

How does that functionality even work though--it doesn't seem to make
sense from a structure point of view. I understand that upon appending
an element to a DOMDocument it probably initializes certain properties
within the DOMElement, but shouldn't I still be able to see those
properties and/or methods as available before I even append it to a
DOMDocument? I'm not even able to see the method appendChild() under
DOMElement (at least before appending the DOMElement to a DOMDocument,
which I have yet to experiment with).