Connecting Tech Pros Worldwide Help | Site Map

why doesn't nodeValue work?

  #1  
Old December 7th, 2007, 08:45 PM
yawnmoth
Guest
 
Posts: n/a
http://www.frostjedi.com/terra/scripts/demo/xml.html

The first alert() shows the XML that the server is returning. The
second alert() shows a particular elements nodeValue and, as you can
see, outputs "null". The third alert() shows a particular elements
textContent. Atleast in Firefox. In Internet Explorer it returns
"undefined".

textContent not working I can understand. Internet Explorer probably
just doesn't implement it. But what about nodeValue? Why doesn't
that work? Both it and textContent work when using PHP's DOM object:

http://www.frostjedi.com/terra/scripts/demo/xml.phps
http://www.frostjedi.com/terra/scripts/demo/xml.php5
  #2  
Old December 7th, 2007, 09:15 PM
VK
Guest
 
Posts: n/a

re: why doesn't nodeValue work?


On Dec 7, 11:44 pm, yawnmoth <terra1...@yahoo.comwrote:
Quote:
http://www.frostjedi.com/terra/scripts/demo/xml.html
>
The first alert() shows the XML that the server is returning. The
second alert() shows a particular elements nodeValue and, as you can
see, outputs "null". The third alert() shows a particular elements
textContent. Atleast in Firefox. In Internet Explorer it returns
"undefined".
>
textContent not working I can understand. Internet Explorer probably
just doesn't implement it. But what about nodeValue? Why doesn't
that work?
If you check
xmlHttp.responseXML.getElementsByTagName("a")[0].nodeType
it will report 1 which is type of an ELEMENT_NODE as any value table
tells us

Both Gecko and IE are very explicit that for element nodes nodeType is
null, so they do exactly what is written:
http://msdn2.microsoft.com/en-us/library/ms534192.aspx
http://developer.mozilla.org/en/docs...ment.nodeValue

Another thing is that the whole behavior
xmlHttp.responseXML.getElementsByTagName("a")[0].nodeValue == null
doesn't have any sense to me, even if it's twenty times standard
compliant: but it is maybe because I am missing something important
out of the Big Picture. It would be nice to have some comments on it
from XML parsing experts. And btw indeed how to get "Hello," from <a>
in more or less cross-browser way?
  #3  
Old December 8th, 2007, 12:05 AM
David Mark
Guest
 
Posts: n/a

re: why doesn't nodeValue work?


On Dec 7, 4:07 pm, VK <schools_r...@yahoo.comwrote:
[snip]
Quote:
>
Another thing is that the whole behavior
xmlHttp.responseXML.getElementsByTagName("a")[0].nodeValue == null
doesn't have any sense to me, even if it's twenty times standard
compliant: but it is maybe because I am missing something important
out of the Big Picture. It would be nice to have some comments on it
You are missing the fact that text nodes are not part of element
nodes. What would you propose the nodeValue of an element node
return?
Quote:
from XML parsing experts. And btw indeed how to get "Hello," from <a>
in more or less cross-browser way?
Can't get blood from stone. If you meant:

<a>Hello,</a>

Then you should know how to get "Hello," from that (the nodeValue
property of the first child of the element node.)
  #4  
Old December 8th, 2007, 05:15 AM
yawnmoth
Guest
 
Posts: n/a

re: why doesn't nodeValue work?


On Dec 7, 5:55 pm, David Mark <dmark.cins...@gmail.comwrote:
Quote:
Quote:
Another thing is that the whole behavior
xmlHttp.responseXML.getElementsByTagName("a")[0].nodeValue == null
doesn't have any sense to me, even if it's twenty times standard
compliant: but it is maybe because I am missing something important
out of the Big Picture. It would be nice to have some comments on it
>
You are missing the fact that text nodes are not part of element
nodes. What would you propose the nodeValue of an element node
return?
In PHP, it seems to return the text node... is PHP wrong?
Quote:
Quote:
from XML parsing experts. And btw indeed how to get "Hello," from <a>
in more or less cross-browser way?
>
Can't get blood from stone. If you meant:
>
<a>Hello,</a>
>
Then you should know how to get "Hello," from that (the nodeValue
property of the first child of the element node.)
That "first child" bit helped. Thanks!
  #5  
Old December 8th, 2007, 05:05 PM
David Mark
Guest
 
Posts: n/a

re: why doesn't nodeValue work?


On Dec 8, 12:13 am, yawnmoth <terra1...@yahoo.comwrote:
Quote:
On Dec 7, 5:55 pm, David Mark <dmark.cins...@gmail.comwrote: Another thing is that the whole behavior
Quote:
Quote:
xmlHttp.responseXML.getElementsByTagName("a")[0].nodeValue == null
doesn't have any sense to me, even if it's twenty times standard
compliant: but it is maybe because I am missing something important
out of the Big Picture. It would be nice to have some comments on it
>
Quote:
You are missing the fact that text nodes are not part of element
nodes. What would you propose the nodeValue of an element node
return?
>
In PHP, it seems to return the text node... is PHP wrong?
Some DOM implementation for PHP returns a text node for the nodeValue
of an element? Yes, that is wrong.
  #6  
Old December 8th, 2007, 07:35 PM
yawnmoth
Guest
 
Posts: n/a

re: why doesn't nodeValue work?


On Dec 8, 10:55 am, David Mark <dmark.cins...@gmail.comwrote:
Quote:
On Dec 8, 12:13 am,yawnmoth<terra1...@yahoo.comwrote:
>
Quote:
On Dec 7, 5:55 pm, David Mark <dmark.cins...@gmail.comwrote: Another thing is that the whole behavior
Quote:
xmlHttp.responseXML.getElementsByTagName("a")[0].nodeValue == null
doesn't have any sense to me, even if it's twenty times standard
compliant: but it is maybe because I am missing something important
out of the Big Picture. It would be nice to have some comments on it
>
Quote:
Quote:
You are missing the fact that text nodes are not part of element
nodes. What would you propose the nodeValue of an element node
return?
>
Quote:
In PHP, it seems to return the text node... is PHP wrong?
>
Some DOM implementation for PHP returns a text node for the nodeValue
of an element? Yes, that is wrong.
I wouldn't say it's just "some" random implementation that's doing
this - it's the implementation that's included with PHP's main
distribution:

http://www.php.net/manual/en/ref.dom.php

ie. it's pretty much the "official" PHP implementation.
  #7  
Old December 8th, 2007, 08:45 PM
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a

re: why doesn't nodeValue work?


yawnmoth wrote:
Quote:
On Dec 7, 5:55 pm, David Mark <dmark.cins...@gmail.comwrote:
Quote:
Quote:
>>Another thing is that the whole behavior
>> xmlHttp.responseXML.getElementsByTagName("a")[0].nodeValue == null
>>doesn't have any sense to me, even if it's twenty times standard
>>compliant: but it is maybe because I am missing something important
>>out of the Big Picture. It would be nice to have some comments on it
>You are missing the fact that text nodes are not part of element
>nodes. What would you propose the nodeValue of an element node
>return?
In PHP, it seems to return the text node... is PHP wrong?
PHP (5)'s DOM extension implements the `nodeValue' property of DOMElement
objects, apparently for convenience, to yield the concatenated node values
of the descendant text nodes of the element node, like the `textContent'
property from W3C DOM Level 3 that it also implements:

http://php.net/DOM

But since it also implements `textContent', `nodeValue' should not yield the
same value. In fact, the value that is yielded there contradicts with W3C
DOM Level 2+ Core that says the `nodeValue' property of objects implementing
the Element interface should have the value `null':

http://www.w3.org/TR/DOM-Level-3-Cor...#ID-1950641247

If it was the intention to implement that interface, that would mean PHP is
wrong here, indeed.


PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
  #8  
Old December 8th, 2007, 09:25 PM
David Mark
Guest
 
Posts: n/a

re: why doesn't nodeValue work?


On Dec 8, 2:33 pm, yawnmoth <terra1...@yahoo.comwrote:
Quote:
On Dec 8, 10:55 am, David Mark <dmark.cins...@gmail.comwrote:
>
>
>
>
>
Quote:
On Dec 8, 12:13 am,yawnmoth<terra1...@yahoo.comwrote:
>
Quote:
Quote:
On Dec 7, 5:55 pm, David Mark <dmark.cins...@gmail.comwrote: Another thing is that the whole behavior
xmlHttp.responseXML.getElementsByTagName("a")[0].nodeValue == null
doesn't have any sense to me, even if it's twenty times standard
compliant: but it is maybe because I am missing something important
out of the Big Picture. It would be nice to have some comments on it
>
Quote:
Quote:
You are missing the fact that text nodes are not part of element
nodes. What would you propose the nodeValue of an element node
return?
>
Quote:
Quote:
In PHP, it seems to return the text node... is PHP wrong?
>
Quote:
Some DOM implementation for PHP returns a text node for the nodeValue
of an element? Yes, that is wrong.
>
I wouldn't say it's just "some" random implementation that's doing
this - it's the implementation that's included with PHP's main
distribution:
>
http://www.php.net/manual/en/ref.dom.php
>
ie. it's pretty much the "official" PHP implementation.
Then the "official" implementation is officially wrong.

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Minidom.Node doesn't call __getattr__ ArseAssassin answers 13 March 9th, 2008 05:39 PM
Why does this javascript xml work in Firefox and not Safari? Tarik Monem answers 3 May 16th, 2007 03:53 AM
Why won't this work sjoshi answers 2 April 3rd, 2007 01:25 PM
SP1 Problem SOAPException doesn't return quote and Umlaute correcty Dany answers 16 November 23rd, 2005 05:16 AM