I have this XML file here.
<?xml version="1.0" encoding="UTF-8"?>
<xml>
<word>
<threeletter>RIP</threeletter>
<threeletter>PIE</threeletter>
<fourletter>PIER</fourletter>
<fourletter>RIPE</fourletter>
<fiveletter>SPIRE</fiveletter>
<sixletter>SPIDER</sixletter>
</word>
<word>
<threeletter>SUE</threeletter>
<threeletter>USE</threeletter>
<fourletter>EMUS</fourletter>
<fourletter>MUSE</fourletter>
<fiveletter>SERUM</fiveletter>
<sixletter>RESUME</sixletter>
</word>
</xml>
And then I will load them and store these words in a array called word once the page is done loading
$(document).ready(function() {
$.ajax
({
url: "dictionary.xml",
success: function( xml )
{
$(xml).find("word").each(function()
{
words.push($(this).text());
});
}
});
})
and then when I access each contents of alert(word[0]) it shows me this result
RIP
PIE
PIER
RIPE
SPIRE
SPIDER
So I am assuming that word[0] is something like this, word[0] = "RIP PIE PIER RIPE SPIRE SPIDER "
but when I do this “
var x = word[0].split(" ");
alert(x[0]);
it is not giving me the word “RIP”
any idea why is this happening? I want to disect all of the words in words[0](that came from an xml) and then split those words and store those words in an array but it seems to be not working any idea why?
May be something like this