# DOM shortcuts

- Thread: https://externals.io/message/32956
- Original archive: https://news-web.php.net/php.internals/32956
- Started by Keryx Web on 2007-10-24T08:56:20+00:00
- Messages: 4
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #32956 — Keryx Web — 2007-10-24T08:56:20+00:00

URL: https://externals.io/message/32956#32956

Hi!

I am trying to understand the internal workings of two PHP-additions to 
the DOM-functionality.

1. 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?

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?

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.

---

## #32960 — Rob Richards — 2007-10-24T10:05:20+00:00

URL: https://externals.io/message/32956#32960 · In reply to: #32956

Hi,

Keryx Web wrote:
> 1. 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.
>
> 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

---

## #32971 — Lars Gunther — 2007-10-24T19:33:01+00:00

URL: https://externals.io/message/32956#32971 · In reply to: #32960

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!

---

## #32972 — Keryx Web — 2007-10-24T19:34:13+00:00

URL: https://externals.io/message/32956#32972 · In reply to: #32960

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!
