Avatar of armasmike
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;

$.ajax({	

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

	  $(xml).find('greeting').each(function(){
             var name_text = $(this).find('fromname').text()
			 	
           
		messageString = "Hi "  +name_text + " ";
		outputField.html(messageString);

						 });	
				
	
				}
	});

Open in new window



and my xml

<?xml version="1.0" encoding="utf-8" ?>
<greeting>
  <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>
  
</greeting>

Open in new window

jQueryXMLWeb Development Software

Avatar of undefined
Last Comment
hielo

8/22/2022 - Mon
Jon Norman

$(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.
armasmike

ASKER
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
$(this).find('fromname').length

but getting it to display one line at a time then do a +1 and go to the next line and so on.
ASKER CERTIFIED SOLUTION
hielo

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Your help has saved me hundreds of hours of internet surfing.
fblack61