Grab XML Image inside Namespace

Asked

Viewed 151 times

2

Hello, I am days trying but unsuccessfully, get only the url of the image of xml down with javascript, XML this one that is of a feed de noticias of Wordpress, to list in another area the newest posts.

<media:content url="http://blog.site.com.br/wp-content/uploads/2014/09/seo-150x150.jpg" width="150" height="150" medium="image" type="image/jpeg"/>

I got the title e o link do xml, but the image within a namespace It’s hard, I’ve tried many ways and last I tried so.

var media = entry['media:content'];

Code JS

dataNovo=new Date();
dataNovo.setDate(dataNovo.getDate()-10);
function loaded_feed_blog(result) {
    if (!result.error) {
        for (var i = 0; i < result.feed.entries.length; i++) {
            var entry = result.feed.entries[i];
            var dataPubli = new Date(entry.publishedDate);

            var media = entry['media:content']; //Aqui minha dificuldade            

            var div = "<div class='media'><a class='pull-left' href='" + entry.link + "' target='_blank'><img class='media-object' src='" + media + "' /></a><div class='media-body'><a href='" + entry.link + "' target='_blank' title='" + entry.title + "'><h4 class='media-heading'><span class='text'>" + truncar_texto(entry.title, 100) + "</span>";         

            if (dataPubli > dataNovo) {
            div += "<span class='label label-success'>Novo</span>";
            }
            div += "<small> - " + formatar_data(dataPubli) + "</small></h4>" + truncar_texto(entry.contentSnippet, 120) + "</a></div></div>";
            $('.changelog-container .box-content').append(div);
        }
    }
}

XML

<item>
    <title>SEBRAE e os Negócios</title>
    <link>
    http://blog.site.br/negocios-virtuais/
    </link>
    <comments>
        http://blog.site.br/negocios-virtuais/#comments
    </comments>
    <pubDate>Tue, 30 Sep 2014 18:16:07 +0000</pubDate>
    <dc:creator>
        <![CDATA[ Shopping ]]>
    </dc:creator>
    <category>
        <![CDATA[ Comércio Eletrônico ]]>
    </category>
    <category>
        <![CDATA[ Produtividade ]]>
    </category>
    <guid isPermaLink="false">http://blog.site.com.br/?p=262</guid>
    <description>
        <![CDATA[
            <p>Normalmente é assim, pelo menos na internet.....</p>
            ]]>
    </description>
    <wfw:commentRss>
        http://blog.site.br/negocios-virtuais/feed/
    </wfw:commentRss>
    <slash:comments>0</slash:comments>
    <media:content url="http://blog.site.com.br/wp-content/uploads/2014/09/seo-150x150.jpg" width="150" height="150" medium="image" type="image/jpeg"/>
</item>

EDIT:

To make the chamada me uso a função down below:

<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script>
    function OnLoad() {
        var feed = new google.feeds.Feed("http://blog.site.com.br/feed/");
        feed.setNumEntries(5);
        feed.load(loaded_feed_blog);
    }
    google.load("feeds", "1");
    google.setOnLoadCallback(OnLoad);
</script>

HTML

<div class="row changelog-itens">
    <div class="box changelog-container alpha">
        <div class="box-header">
            <h2 class="pull-left">Direto do BLOG</h2>
            <div class="box-widget pull-right">
                <a href="http://blog.site.com.br/" target="_blank" class="btn btn-link" style="font-size: 13px; margin: 4px -10px 0 0;">Ver mais</a>
            </div>
        </div>
        <div class="box-content"></div>
    </div>
</div>

How can ver na imagem below, is listing straight, but quebra a imagem.

ver na imagem

  • How are you receiving this XML? via ajax? in a string?

  • Hello @Sergio, I edited the question and put all the codes that makes the process of reading the XML and the image, already graded.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.