Reputation: 3393
I am using the following jQuery to get the <title>
and <content>
of an xml feed, for the var contentimg = $(this).find('content').text().find("img").attr("src")
there is nothing being returned however if i am to change the variable to $(this).find('content').text()
; i am returned the entire content when i am only looking for the content's images src atrribute value.
$(document).ready(function () {
$.ajax({
type: "GET",
url: "http://www.blogger.com/feeds/2399953/posts/default",
dataType: "xml",
success: xmlParser,
dataType: 'jsonp'
});
});
function xmlParser(xml) {
$(xml).find("entry").each(function () {
var title = $(this).find('title').text();
var contentimg = $(this).find('content').text().find("img").attr("src");
$(".entirecont").append('<br/>'+title+'<br/>'+contentimg+'<br/><br/><br/>');
});
}
Upvotes: 0
Views: 1633
Reputation: 921
You have several errors in your code:
Here is a working example (without images from the feed, but that should be self-explaining)
$(document).ready(function () {
$.ajax({
type: "GET",
url: "http://www.blogger.com/feeds/2399953/posts/default",
dataType: "xml",
success: function(xml) {
xmlParser(xml)
},
dataType: 'jsonp'
});
});
function xmlParser(xml) {
parsedxml = $.parseXML(xml)
xml = $(parsedxml)
entries = xml.find("entry").each(function(key, value) {
title = $(value).find("title").text()
$("body").append(title)
$("<br>").appendTo("body")
})
}
Upvotes: 0
Reputation: 15034
The content in the <content>
tag is encoded. You need to unescape
it:
var contentimg = $(unescape($(this).find('content').text())).find("img").attr("src");
Upvotes: 1