Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Javascript DOM (Google & Safari) childNodes

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

Create CentOS 7 Newton Packstack Running Keystone

A bug was filed against RDO for the installation of Keystone v3. This guide is designed to walk you through the configuration for using Keystone v3 with Packstack. You will accomplish this using various repos and the Answers file.

Question has a verified solution.

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

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

715 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