Closed Bug 122681 Opened 24 years ago Closed 24 years ago

XML DOM Javascript .nodeValue Null

Categories

(Core :: DOM: HTML Parser, defect)

x86
Windows 2000
defect
Not set
normal

Tracking

()

VERIFIED INVALID

People

(Reporter: xmlguy, Assigned: harishd)

Details

Attachments

(5 files, 5 obsolete files)

I have "walked the DOM" with Javascript. When I get to a text node and use nodeValue to get the contents, it returns null when it should return the contents. I have doulbe checked with javascript to do this when the nodeType ==3. I have tried to use .text with .innerHTML. That doesn't work either.
Please attach a test case.
Attached file HTML files with Javascript (obsolete) —
This is the HTML file w/ javascript
Attached file 2nd Test Case (obsolete) —
This uses a different XML file, same exact structure and contents. Compare Instructor.xml to Instructor1.xml then view instr.html vs instr2.html. There are Parsing problems. This probably goes beyond the scope of BUG 122681
Attached file goes with instr2.html
Read comments on attachment 67155 [details]
Attachment #67155 - Attachment mime type: text/plain → text/html
Attached file Fixed 1st Test Case (obsolete) —
Attachment #67168 - Attachment is obsolete: true
Finally got it right. Ok, there were several problems in the testcases. In short, Mozilla is doing the right thing and your script needs to be modified. Read on: 1. Mozilla's document.load() executes asynchronously (in IE you can choose). Therefore, you MUST set an onload handler to be called before you initiate the load(). Otherwise you have no idea when the document is loaded and when you can use it. 2. You were going past the length of the ndes array, and using the property every time in the loop is a (small) perf hit. 3. In XML whitespace between elements is generally not removed. Therefore, the empty text nodes you were seeing between each element were the newline text nodes. 4. The nodeValue of element name was empty, as expected (I think, I should really check the spec whether or not it should be empty or contain the element name). You probably wanted all of the nodeValues of the element's child text nodes concatenated. In the last testcase I attached, I show how you get the firstChild's nodeValue (which is a text node). You can probably elaborate from there... Also, in the future when you attach test cases, it would be nice if you could first attach the XML files that are referenced by other files, and then attach the "driver" file last using the correct URLs to the earlier attachments. That way, I can test just by clicking on the last attachment link without needing to download all of them into my computer. Anyway, thanks for your interest in Mozilla. It's great you took the effort to file a bug and provide testcases!
Status: UNCONFIRMED → RESOLVED
Closed: 24 years ago
Resolution: --- → INVALID
Well, I thought it was resolved, because I found an answer to my problem, but.. <INFO>some information</INFO> is actually 2 or 3 nodes, however you look at it. if I get to "some information" it has a nodeType of 3, and so it can then be used with .nodeValue. YOu should not have to say Element.firstChild.nodeValue. It should just be Node.NodeValue. http://www.mozilla.org/docs/dom/domref/dom_el_ref17.html#1018663 also from a previous email, the nodeValue of an Element is null, but not for a text node. Marc Certified XML Developer and Related Technologies
Status: RESOLVED → UNCONFIRMED
Resolution: INVALID → ---
The documentation you linked to is misleading at best. The only useful thing there is that there is a link to the specification near the bottom (http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-F68D080). The specification says: Interface nodeValue ---------------------------------------------- Attr value of attribute CDATASection content of the CDATA Section Comment content of the comment Document null DocumentFragment null DocumentType null Element null NamedNodeMap null EntityReference null Notation null ProcessingInstruction entire content excluding the target Text content of the text node So returning null for an Element node is in fact correct. Bug 122741 filed on the documentation people.
Status: UNCONFIRMED → RESOLVED
Closed: 24 years ago24 years ago
Resolution: --- → INVALID
Verified Invalid
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: