RSS .92| RSS 2.0| ATOM 0.3
  • Home
  • About Me
  • My Publications
  • My Work Domain
  • phpResource Feeds

    Some Usage Examples of My XmlToArray Class

    I am very happy that my XmlToArray Class at PHPClasses.Org got a huge popularity. This class parses XML and forms array from the hierarchical XML format. You can download it from here:

    Recently few users requested me to provide a real-life example usage of my class. In this regard, I want to show two examples here:

    BBC News Feed :

    Cricinfo Latest :

    Screenshot of XmlToArray Usage Example
    I want to share my usage.php that I used for BBC News Feed. Here it is:


    // Retrieving the RSS first. I used file_get_contents(), you can retrieve by any other way
    $xml_data = file_get_contents(“ newsonline_world_edition/front_page/rss.xml”);

    //Creating Instance of the Class
    $xmlObj = new XmlToArray($xml_data);

    //Creating Array
    $arrayData = $xmlObj->createArray();

    $rssData = array();
    //getting the feed items
    $rssData = $arrayData[‘rss’][‘channel’][0][‘item’];

    // data is available; loop through the data

    foreach($rssData as $i=>$v)

    $title = $v[‘title’];
    $link = $v[‘link’];
    $category = $v[‘category’];
    $pubDate = $v[‘pubDate’];
    $desc = $v[‘description’];

    /* print data now


    Isn’t this the simplest script? Yes, I tried to make it as simple as possible. Please feel free to let me know more queries.

    Best regards.


    Leave a Reply

    You must be logged in to post a comment.