Solved

Javascript DOM (Google & Safari) childNodes

Posted on 2013-05-23
5
429 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Power Action 2 46
allow link tag to be submit like form 15 60
Load XML element 3 43
How can I get a list of all files of a network drive sorted by date created/modified? 24 72
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

751 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