473,396 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Traversing XML with Javascript

6
Hi team I'm traversing an XML file with 3000 + records in it. I've now run into some serious performance issues as a consequence... Is there an alternative to the below code I'm using? Or is there something in here that is really slowing it down? Any help would be much appreciated, it is currerntly taking 15 seconds to traverse my XML file!!!

XML FILE
Expand|Select|Wrap|Line Numbers
  1. <supplier>
  2. <id>001</id>
  3. <name>My Supplier</name>
  4. </supplier>
  5. <supplier>
  6. <id>002</id>
  7. <name>Another One</name>
  8. </supplier>
JAVASCRIPT
Expand|Select|Wrap|Line Numbers
  1. xmlDoc.validateOnParse = false;
  2. xmlDoc.resolveExternals = false;
  3. xmlDoc.preserveWhiteSpace = false;
  4. xmlDoc.async = false;
  5. xmlDoc.load(suppliers.xml);
  6. xmlObj = xmlDoc.documentElement;
  7.  
  8. // THIS IS THE DIV WHERE THE SUPPLIERS ARE PRINTED
  9. var aPrint = document.getElementById("items");
  10.  
  11. // AND WE LOOP THROUGH ALL 3000 OF THEM HERE
  12. for (var i=0; i<xmlObj.childNodes.length;i++)
  13. {
  14. var sDiv = document.createElement("div");
  15. sDiv.setAttribute("id","item" + i);
  16. sDiv.innerHTML = sDiv.innerHTML + "<h2>" + xmlObj.childNodes(i).childNodes(0).text + "</h2>";
  17. sDiv.innerHTML = sDiv.innerHTML + "<h3>" + xmlObj.childNodes(i).childNodes(1).text + "</h3>";
  18. var sBreak = document.createElement("hr");
  19. sDiv.appendChild(sBreak);        
  20. aPrint.appendChild(sDiv);
  21. }
Dec 12 '07 #1
5 2097
jkmyoung
2,057 Expert 2GB
Unfortunately, javascript tends to be very slow. Have you tried using another tool such as XSLT instead?
Dec 12 '07 #2
tonecj
6
Thanks for the tip! The data comes straight in using XSL, no loading time at all.

Much appreciated!

Last question for the day, I'm currently googling it with little luck, is there a way to use XSL to do a search on the XML file based on text in a textbox?

Thanks
Dec 12 '07 #3
tonecj
6
I've managed to get no where today with the search... Does anyone know how I can pass the value of a textbox to an xsl:param???

What I'm trying to do now is:

<xsl:if test="contains(name, 'MYSEARCHSTRING'">

Where MYSEARCHSTRING is the value in a text box.

Thanks again!
Dec 13 '07 #4
jkmyoung
2,057 Expert 2GB
Are you running the xsl transformation in javascript?

Generally the syntax is like:
Expand|Select|Wrap|Line Numbers
  1. xslProc.addParameter("sortOrder", myvalue);
Dec 13 '07 #5
tonecj
6
That's it, works perfectly.

Thanks!
Dec 17 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: lothar | last post by:
i want to traverse a set of messages in a Yahoogroups group from a Python program. to get to the messages of the group, one must log in. this presents, i think, two problems, 1) handling the...
3
by: Plamen Valtchev | last post by:
This is my problem: From JavaScript I want to find the list of all defined/loaded JavaScript functions/objects/names within the current scope (html page in a browser). the page could contain...
1
by: X | last post by:
I cannot figure this one out. I would like to traverse through and elements styles (not class) and get a list of all properties using javascript property names and css property names along with the...
4
by: plmanikandan | last post by:
Hi, I am new to link list programming.I need to traverse from the end of link list.Is there any way to find the end of link list without traversing from start(i.e traversing from first to find the...
4
by: Christian Rühl | last post by:
Good Day, folks! I'm having a problem traversing an XmlDocument tree in C#. I only want to access the InnerText of the leafs and the names of their ancestors and show them in a richTextBox. But...
10
by: Rik | last post by:
Hi all, I usually don't really use javascript, but for a pretty big form, I'm trying the following: I've got arbitrarily deep nested unorderd list, with in every <li3 checkboxes. It's for...
7
BlueEagle
by: BlueEagle | last post by:
hi to all! I hv added a TreeView Control on my page in Asp.net 2.0 and i want to move through the Tree in JavaScript Anyone hv an idea Advance Thanks BlueEagle
30
by: asit | last post by:
We kno that data can be pushed onto the stack or popped 4m it. Can stack be traversed ??
1
by: somcool | last post by:
I am facing an error while traversing a query in MS Access Details - When I click a button, a form which has the query opens up. There are certain fields which are in the form of combo box in the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.