Grow your CSS skills. Land your dream job.

Grabbing data from xml

  • # June 21, 2013 at 4:31 pm

    Is there a way you can grab specific data from an RSS feed (XML) and output that specific data?

    What I’d like to do is grab the latest article in my list (there will be multiples) and output specific information. Such as the article title and URL.

    # June 21, 2013 at 4:34 pm

    Damn. Let me google this first in case I can answer my own question.

    # June 21, 2013 at 5:19 pm

    you will handle this on the client or server?
    i find it always more readable having the data in json format.

    xml to json with php http://stackoverflow.com/questions/8830599/php-convert-xml-to-json

    xml to json with javascript http://davidwalsh.name/convert-xml-json

    # June 21, 2013 at 5:34 pm

    SimplePie can parse the XML data. http://simplepie.org/

    # June 21, 2013 at 5:41 pm

    Thanks @pixelgrid. Just caught that post as well. PHP is what I’m looking for.

    # June 21, 2013 at 5:43 pm

    Also, thanks @AlenAbdula. I’d rather not download anything for something this simple. It does look quite useful, though.

    # June 21, 2013 at 6:05 pm

    Solved.

    < ?php

    $xml = simplexml_load_file(“http://site.com/feed”);
    $json = json_encode($xml);
    $array = json_decode($json,TRUE);
    var_dump ($array);
    ?>

    # June 21, 2013 at 6:31 pm

    Okay. So, how could I output the content in the last array?

    http://cloud.chrisburton.me/image/0o2k1w2X0r2H

    # June 21, 2013 at 8:31 pm

    lets say your array of data is named $data

    so item is

    $item = $data;
    foreach($item as $key=>$value){
    //handle title,link etc.
    }

    # June 21, 2013 at 9:08 pm

    > lets say your array of data is named $data – @pixelgrid

    What do you mean by this?

    # June 21, 2013 at 9:44 pm

    Nevermind, I understand now. Thanks @pixelgrid.

Viewing 11 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".