Solved

Javascript DOM (Google & Safari) childNodes

Posted on 2013-05-23
5
433 Views
Last Modified: 2013-05-28
I have an xml structure which looks like this:

<items>
 <item id="1">
     <item id="44">
         <item id="3"></item>
         <item id="4"></item>
     </item>
     <item id="99"></item>
</item>
</items>

Open in new window


With reference to above. For Google chrome and safari I am having trouble with the javascript childNodes property. Say I have item id="1" in my xml object. I want to iterate through and get the immediate childNodes. So 44 & 99 not 3 and 4. If I had 44 in my xml object then immediate children would be 3 and 4.

This works fine in IE using
var myEl = this.xmlData.selectSingleNode('//*[@id=' + pId + ']');
            for (var i = 0; i < myEl.childNodes.length; i++) {
               // do something
            }

Open in new window


In google chrome childNodes picks up eveything, all the childrens childrens aswell which is no good. Any ideas??
0
Comment
Question by:kbuss
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 500 total points
ID: 39191345
There are hundreds (probably thousands) of complaints of buggy implementation of childNodes in Chrome.

if you Google chrome xml childnodes you will see there are a large number of issues trying to use childNodes because it appears that Chrome looks like it treats all descendent elements as children.  There are also issues with counting white space as text nodes within child nodes.  If you search through enough of the posting and bug reports you might find a solution or workaround or hack you can use.

One thing you could do if you have control of the xml is to use different tag names for different levels so you could use getElelemntsByTagName, or add an attribute to indicate level that you could test.

Cd&
0
 

Author Comment

by:kbuss
ID: 39193653
I've requested that this question be deleted for the following reason:

I managed to resolve this myself. The single comment that was left was of no use whatsoever. So I would like the question deleted. I also do not want to provide the solution for others to use.
0
 
LVL 2

Expert Comment

by:laurent_roy
ID: 39193654
The comment was helpful, it gives an explanation.
Why did you ask for help if you don't want to give your solution ? Do you think you will get help on next time ?
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 39194758
The "Exchange" in Experts-Exchange is the underlying principle of the community and the site.  The volunteers who provide support are here because we believe in the free flow of information that benefits ALL members of the community.  

If kbuss is not interested in being part of a sharing community then they don't belong on the site.

Cd&
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question