Some Usage Examples of My XmlToArray Class

July 4, 2007 § 7 Comments

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(“”);

//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.


§ 7 Responses to Some Usage Examples of My XmlToArray Class

  • cabbar says:

    What about nodes more than one? i mean, if there are siblings it gives only the last node and its descents as an array. eg.

    only the 3rd stock node returns as array.

  • rss says:

    thank you very much

  • music says:

    very interesting.
    i’m adding in RSS Reader

  • fanis says:

    i try to send via POST this:

    $xmlObj = new XmlToArray( addslashes( $_POST[‘xmls’]) );

    $arrayData = $xmlObj->createArray();


    but nothing doit??

    when i try this, i have no problem??:

    $xml_data = ”



  • Wolfgang says:

    I just came across this really great script. Thank you. The only problem I have is the one that cabbar described above (gives you only the last node if there are siblings). I haven`t found a newer script than 1.0. Is there a solution for this?

  • Rupom says:

    Yes as it converts xml into array, only the last one gets placed for the same named nodes (you know two same level indexes can’t have same index name). Please give me your example XML that you faced problem for. I will give you a solution.


  • Bill Bartmann says:

    Excellent site, keep up the good work.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

What’s this?

You are currently reading Some Usage Examples of My XmlToArray Class at Rupom Here.



Get every new post delivered to your Inbox.

Join 178 other followers

%d bloggers like this: