Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6580633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:03:10+00:00 2026-05-25T16:03:10+00:00

I have an issue parsing an XML feed – The following code attempts to

  • 0

I have an issue parsing an XML feed – The following code attempts to parse an XML feed and populate a page with news data. The issue I have is that the description node is HTML encoded and I need to strip out the src of an img tag contained within it ( just one image tag is contained within each description node).

I have limited knowledge of regular expression – but I tried to use a filter approach to strip out the src code – but the below example doesn’t work.

Any help would be gratefully received as I’m pulling my hair out with this one!

$(xml).find("item").each(function() {
    var i = $(xml).find("item").index(this);

    var imgStripSrc = $('item:eq(1) description', xml).filter(function() {
        return /(?: src=")(.+)(?:")/
    })

    if (i < 1) {
        var newsTitleOne = $('item:eq(0) title', xml).text();
        if (newsTitleOne.length > 40) {
            newsTitleOne = newsTitleOne.substring(0, 30) + "..";
        }
        $(".newsIOne .newsText .t").empty();
        $(".newsIOne .newsText .t").append(newsTitleOne);
    } else {
        var newsTitleGen = $('item:eq(' + i + ') title', xml).text();
        if (newsTitleGen.length > 80) {
            newsTitleGen = newsTitleGen.substring(0, 74) + "..";
        }
        var newsTitleLinkHid = $('item:eq(' + i + ') link', xml).text();
        var newsRow = $('<div class="newsRow"><a href="' + newsTitleLinkHid + '" target="_blank">' + newsTitleGen + '</a><img src=' + imgStripSrc + '/></div>');
        $(".newsRows").prepend(newsRow);
    }
});

XML example here – http://fb.mobilechilli.com/chilli_news_reviews/NewsReviews%20Build/tstXML.xml

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T16:03:10+00:00Added an answer on May 25, 2026 at 4:03 pm

    You can make use of the fact that jQuery can build a DOM from an HTML string and therefore you do not need to fiddle with regexes at all. I rewrote your code:

    $(".newsIOne .newsText .t").empty();
    $(xml).find("item").each(function(i) {
        var html     = $( $("description", this).text() ), 
            imgsrc   = $("img:first", html).attr("src"),
            title    = $("title", this).text(),
            link     = $("link", this).text(),
            ellipsis = String.fromCharCode(8230);
    
        if (i == 0) {
            if (title.length > 40) {
                title = $.trim( title.substring(0, 30) ) + ellipsis;
            }
            $(".newsIOne .newsText .t").text(title);
        } else {
            if (title.length > 80) {
                title = $.trim( title.substring(0, 74) ) + ellipsis;
            }
            $(".newsRows").prepend(
                $('<div class="newsRow">')
                .append("<a>", {target: "_blank",  href: link, text: title});
                .append("<img>", {src: imgsrc});
            );
        }
    });
    

    Notes

    • this always refers to the current element you are working on, so in the body of each() you do not have to juggle around those $('item:eq(' + i + ') title', xml).
    • $(description, this).text() fetches the HTML string, wrapping it in another $() creates a DOM from it. You can operate on that to find your <img>
    • There is an actual ellipsis character ("…"), use it.
    • Build HTML from concatenated strings at your own peril. I’ve used the convenient helper functions jQuery has built-in instead.
    • The loop index is passed in as an argument from each(), no need to find/count it yourself.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi BB developers I have a issue while parsing the xml data using DOM.
I have a strange issue, when it comes to parsing XML with NSXMLParser on
I have a weird issue. I receive the following error that causes a force-close:
I have an xml file in which it is possible that the following occurs:
I have an xml document. When parsing that doc I want to do <c:set
I have issue that is reproduced on g++. VC++ doesn't meet any problems. So
I have an issue that is driving me a bit nuts: Using a UserProfileManager
We have an issue on our page whereby the first time a button posts
I have an issue with watin test that should browse for pdf and upload
I am trying to parse an rss feed that is using the well formed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.