473,545 Members | 769 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Traversing XML with Javascript

6 New Member
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 2102
jkmyoung
2,057 Recognized Expert Top Contributor
Unfortunately, javascript tends to be very slow. Have you tried using another tool such as XSLT instead?
Dec 12 '07 #2
tonecj
6 New Member
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 New Member
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 Recognized Expert Top Contributor
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 New Member
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
2920
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 form element for the login, which has a javascript submit routine, 2) keeping login state with cookies.
3
1942
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 many included javascript with the script tag : <script language="javascript" src="XXX/Script.js"></script>
1
1444
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 corresponding values. I cannot figure this out, it seems like it should be easy. Everything out there only shows when people know the property...
4
4864
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 next for null).Is there any way to find the length of linked list in c.My need is to traverse from the end to 5th node Regards, Mani
4
5510
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 if I go like this I get the InnerText of all the nodes and the outcome in my richTextBox is just a mess. The XML files i want to handle here have...
10
4263
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 granting users certain rights, and rights are inherited (or unset) downwards. To directly illustrate what certain changes will do for the user, I...
7
3294
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
4251
by: asit | last post by:
We kno that data can be pushed onto the stack or popped 4m it. Can stack be traversed ??
1
1518
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 query. The query comes from a table which picks values from another table. When I try traversing the query through TAB button, I get the following...
0
7656
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7416
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5969
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5325
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4944
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3449
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1878
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1013
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
701
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.