469,632 Members | 1,639 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,632 developers. It's quick & easy.

why doesn't nodeValue work?

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
Dec 7 '07 #1
7 5817
VK
On Dec 7, 11:44 pm, yawnmoth <terra1...@yahoo.comwrote:
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?
Dec 7 '07 #2
On Dec 7, 4:07 pm, VK <schools_r...@yahoo.comwrote:
[snip]
>
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?
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.)
Dec 8 '07 #3
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

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?
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!
Dec 8 '07 #4
On Dec 8, 12:13 am, yawnmoth <terra1...@yahoo.comwrote:
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
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.
Dec 8 '07 #5
On Dec 8, 10:55 am, David Mark <dmark.cins...@gmail.comwrote:
On Dec 8, 12:13 am,yawnmoth<terra1...@yahoo.comwrote:
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
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.
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.
Dec 8 '07 #6
yawnmoth wrote:
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
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
Dec 8 '07 #7
On Dec 8, 2:33 pm, yawnmoth <terra1...@yahoo.comwrote:
On Dec 8, 10:55 am, David Mark <dmark.cins...@gmail.comwrote:


On Dec 8, 12:13 am,yawnmoth<terra1...@yahoo.comwrote:
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
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.

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.

Dec 8 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Chewy509 | last post: by
4 posts views Thread by Chris Lount | last post: by
6 posts views Thread by JustSomeGuy | last post: by
3 posts views Thread by Iver Erling Årva | last post: by
10 posts views Thread by Brett | last post: by
3 posts views Thread by Joey | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.