Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Javascript DOM (Google & Safari) childNodes

Posted on 2013-05-23
5
Medium Priority
?
452 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 2000 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

926 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