Solved

Javascript DOM (Google & Safari) childNodes

Posted on 2013-05-23
5
415 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
  • 2
5 Comments
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now