I have a list of quotes in an XML document. Each quote is wrapped like this:
<Item>
<Quote>This is a quote!</Quote>
<Source>-- this is the Source of the Quote!</Source>
</Item>
Here's the jQuery:
var html = '';
var tmpl = '<li class=""><p class="quote">__quote</p><p class="source">__source</p></li>';
$(quoteObj).find('Item').each(function(){
$that = $(this);
var _quote = $that.children('Quote').text();
var _source = $that.children('Source').text();
var qhtml = tmpl.replace('__quote', _quote).replace('__source', _source);
html += qhtml;
});
return html;
In the end product, the QUOTES are all there, but the SOURCES aren't. I can't for the life of me figure out why. What's right in front of me that I can't see?
ADDITIONAL INFORMATION TO ANSWER COMMENTS:
- The XML is properly formed, and I changed it above.
- I added the
var tmplline to show what I'm replacing in the loop. The__quoteis being replaced, and the__sourceis at least being acted upon, since the second<p>is empty, instead of containing a string. - I have checked the actual XML coming back from the AJAX call, and it is all there, as it should be.
It seems to me this is some sort of issue with scoping and this, or with the action of the .children() method, but I still can't find it.
ONE LAST NOTE:
Changed the XML tag case to Initial Caps, which it is in the document in question.