why doesn't nodeValue work?

Y

yawnmoth

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
 
V

VK

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/DOM:element.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?
 
D

David Mark

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.)
 
Y

yawnmoth

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?
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!
 
D

David Mark

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.
 
Y

yawnmoth

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.
 
T

Thomas 'PointedEars' Lahn

yawnmoth said:
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-Core/core.html#ID-1950641247

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


PointedEars
 
D

David Mark

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top