Closed
Bug 368167
Opened 18 years ago
Closed 18 years ago
Iterating through an xml document: element.childNodes[0].firstChild has no properties.
Categories
(Firefox :: General, defect)
Tracking
()
People
(Reporter: andries.nieuwenhuize, Unassigned)
References
()
Details
Attachments
(1 file)
1.88 KB,
text/html
|
Details |
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; nl; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1 Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; nl; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1 There seems to be a problem with the index 0. For example iterating through an xml document (element.childNodes[0].firstChild.nodeValue) won't work. It does well in IE7 and (element.childNodes[1].firstChild.nodeValue)works but different than it is supposed to be. The childNode[0] does not exist in firefox2 and childNode[1] is seen as childNode[0]. The workaround that I currently use is (element.getElementsByTagName("tagname")[0]) instead of element.childNode[0] and this works well. Reproducible: Always Steps to Reproduce: 1. Make an xml-doc with the followin structure: <?xml version="1.0" encoding="UTF-8"?> <site> <page id="home"> <title>Home</title> <content>Welcome to my site.</content> </page> </site> 2. Try to catch the data when loaded: var elDocRoot=xmlDoc.getElementsByTagName("site")[0]; for (var i=0; i<elDocRoot.childNodes.length; i++) { elChild=elDocRoot.childNodes[i]; if (elChild.nodeName=="page") { //title=elChild.getElementsByTagName("title")[0].firstChild.nodeValue; //workaround title=elChild.childNodes[0].firstChild.nodeValue; content=elChild.childNodes[1].firstChild.nodeValue; window.alert(title); } } 3. Actual Results: Fout: elChild.childNodes[0].firstChild has no properties elChild.childNodes[1].firstChild.nodeValue="Home"; Expected Results: elChild.childNodes[1].firstChild.nodeValue="Welcome to my site"; I think for AJAX-websites this could be a major bug!!!
Reporter | ||
Comment 1•18 years ago
|
||
If jou run the index.html mind to set the proper docroot in buggy.js on line 6. After (or meanwhile) loading you can view the problem in the errorconsole.
Comment 2•18 years ago
|
||
element.childNodes[0] will return the whitespace between the tags.
Status: UNCONFIRMED → RESOLVED
Closed: 18 years ago
Resolution: --- → DUPLICATE
You need to log in
before you can comment on or make changes to this bug.
Description
•