Link to home
Start Free TrialLog in
Avatar of armasmike

asked on

jquery xml loop though each node

i am trying to loop though all the node one at a time. How do i count how many node are in the xml file

There are 7 <fromname>Chris Gannon </fromname>

i need it to count then display the first one and then the next time it loads display then the next one and so on.

How do i do that ?

// insert code for loaded event here
var fromName;
var outputField = $(this.lookupSelector("xmlOutput"));
var messageString;


	type: "GET",
	url: "sampleoutput.xml",
	dataType: "xml",
	success: function(xml) {

             var name_text = $(this).find('fromname').text()
		messageString = "Hi "  +name_text + " ";


Open in new window

and my xml

<?xml version="1.0" encoding="utf-8" ?>
  <fromname>Chris Gannon </fromname>
  <fromname>Chris Gannon </fromname>
  <fromname>Chris Gannon </fromname>
  <fromname>Chris Gannon </fromname>
  <fromname>Chris Gannon </fromname>
  <fromname>Chris Gannon </fromname>
  <fromname>Chris Gannon </fromname>

Open in new window

Avatar of Jon Norman
Jon Norman
Flag of United Kingdom of Great Britain and Northern Ireland image

$(this).find('fromname').length should give the number of elements.

$($(this).find('fromname')[2]) should be the third element (it's zero based)

you will need find someway of storing which one (index) you have displayed (maybe in a cookie) and then display the next.
Avatar of armasmike


I am using a program call Adobe edge it uses jquery as it's main code. Like ac3 is to flash i am trying try to recreate my flash animation that reads a xml file and display the text.

this works

but getting it to display one line at a time then do a +1 and go to the next line and so on.
Avatar of hielo
Flag of Wallis and Futuna image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial