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 ?
and my xml
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);
});
}
});
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>
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').l ength
but getting it to display one line at a time then do a +1 and go to the next line and so on.
this works
$(this).find('fromname').l
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
$($(this).find('fromname')
you will need find someway of storing which one (index) you have displayed (maybe in a cookie) and then display the next.