Hi!
I am trying to understand the internal workings of two PHP-additions to
the DOM-functionality.
-
When using the shortcut DOMElement::nodeValue on an element node,
where the standard says DOMElement::firstChild::nodeValue, is there any
difference whatsoever between DOMElement::nodeValue and
DOMElement::textContent? -
Using this as well as the the non-standard last parameter on
DOMDOcument::createElement and DOMDOcument::createElementNS, am I taking
advantage of some magic in libxml2 or is this invented by you PHP guys,
as was my guess?
If so, are these feature available in any other language or library?
I've checked Gdome, Perl XML::DOM, Perl XML::LibXML::DOM and Java, as
well as every major browser and the answer so far seems to be no.
I am asking this as especially the first one seem to be a very
convenient shortcut and I will lobby the What-WG/W3C to make it part of
the standard.
Lars Gunther
P.S. I have looked at
http://cvs.php.net/viewvc.cgi/php-src/ext/dom/document.c?revision=1.68.2.3.2.5.2.2&view=markup
But since (a) I am a real newbie in C and (b) I do not know where
"xmlNewDocNode" comes from - the best I can manage is an educated guess.
Hi,
Keryx Web wrote:
When using the shortcut DOMElement::nodeValue on an element node,
where the standard says DOMElement::firstChild::nodeValue, is there any
difference whatsoever between DOMElement::nodeValue and
DOMElement::textContent?
None whatsoever. nodeValue on an element was added for convenience.
textContent was a Level 3 method and not implemented until later on. The
initial focus when DOM was being developed was Level 1 and Level 2.Using this as well as the the non-standard last parameter on
DOMDOcument::createElement and DOMDOcument::createElementNS, am I taking
advantage of some magic in libxml2 or is this invented by you PHP
guys, as was my guess?
This was added to save PHP developers time. In most cases, elements
contain simple text content (not mixed node types). Allowing the element
to be created along with its content saves some time and coding when
creating/editing documents. No magic involved. In fact libxml2 had a
single function to do this.If so, are these feature available in any other language or library?
I've checked Gdome, Perl XML::DOM, Perl XML::LibXML::DOM and Java, as
well as every major browser and the answer so far seems to be no.
Unknown, though probably not. I added them strictly for the convenience
of PHP developers.I am asking this as especially the first one seem to be a very
convenient shortcut and I will lobby the What-WG/W3C to make it part
of the standard.
These would most certainly not make the standard. The first already
exists in the form of textContent in Level 3 specs. The second is a
limited piece of functionality for creating content within an element.
Although this is the type of document the majority of PHP developers are
using (only basing this on experience and feedback from people), content
is sometimes much more complex than this, so I doubt a parameter
limiting functionality this much would be added.
Rob
Rob Richards skrev:
These would most certainly not make the standard. The first already
exists in the form of textContent in Level 3 specs.
The first one was not on my agenda. Sorry for my lack of clarity.
The second is a
limited piece of functionality for creating content within an element.
Although this is the type of document the majority of PHP developers are
using (only basing this on experience and feedback from people), content
is sometimes much more complex than this, so I doubt a parameter
limiting functionality this much would be added.
I do think JavaScripters (et al) will enjoy the same convenience! Many
PHP-developers write JavaScript, too.
In what way will the second parameter limit functionality, if it's
optional?
Going off topic:
If anyone is interested, here is the link to the discussion I started on
the WHAT-WG mailing list:
http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2007-October/012841.html
As an example of why I think WHAT-WG is an appropriate place to suggest
this feature is the new method getElementsByClassName. Firefox 3.0 will
the first browser to support the this addition to the W3C-DOM spec.
Opera and Safari will soon follow as there are great speed improvements
to be won having it natively:
http://ejohn.org/blog/getelementsbyclassname-speed-comparison/
Lars Gunther
BTW, Rob, I've read your book. Great stuff!
Rob Richards skrev:
These would most certainly not make the standard. The first already
exists in the form of textContent in Level 3 specs.
The first one was not on my agenda. Sorry for my lack of clarity.
The second is a limited piece of functionality for creating content
within an element. Although this is the type of document the majority of
PHP developers are using (only basing this on experience and feedback
from people), content is sometimes much more complex than this, so I
doubt a parameter limiting functionality this much would be added.
I do think JavaScripters (et al) will enjoy the same convenience! Many
PHP-developers write JavaScript, too.
In what way will the second parameter limit functionality, if it's
optional?
Going off topic:
If anyone is interested, here is the link to the discussion I started on
the WHAT-WG mailing list:
http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2007-October/012841.html
As an example of why I think WHAT-WG is an appropriate place to suggest
this feature is the new method getElementsByClassName. Firefox 3.0 will
the first browser to support the this addition to the W3C-DOM spec.
Opera and Safari will soon follow as there are great speed improvements
to be won having it natively:
http://ejohn.org/blog/getelementsbyclassname-speed-comparison/
Lars Gunther
BTW, Rob, I've read your book. Great stuff!