Solved

joomla xml parser module

Posted on 2011-03-08
5
922 Views
Last Modified: 2012-05-11
Hi,

I've been searching for a while and can't seem to find a way to actually create a joomla 1.6 module (xml parser).
I actually need to retrieve information from this xml: link

fyi only from one of these servers I need to retrieve information, not all of them.

How do I proceed? Also how should I put this in a module for joomla 1.6?

regards
0
Comment
Question by:Mutsop
  • 3
  • 2
5 Comments
 
LVL 3

Author Comment

by:Mutsop
ID: 35080449
k so I actually started on my own... but came onto a little problem:

It's the first time I'm trying to build a module for joomla 1.6.
So to ease my work I just copied the basic of the rss feed module.

Now, I'm trying to read an xml file (from an url) and show these information on my website.

So here is the code (I suppose you don't really need the default.php and xml of the options).

mod_xmlreader.php:
<?php
// no direct access
defined('_JEXEC') or die;

// Include the syndicate functions only once
require_once dirname(__FILE__).DS.'helper.php';

$status = modXmlreaderHelper::getStatus($params);
require JModuleHelper::getLayoutPath('mod_xmlreader');

Open in new window


helper.php:
<?php
// no direct access
defined('_JEXEC') or die;

class modXmlreaderHelper
{
	static function getStatus()
	{
		error_reporting(E_ALL);
		echo "<pre>" . PHP_EOL;

		// TEST DATA FROM THE POST AT EE
		$url = "http://eu.riftgame.com/en/status/eu-status.xml";

		// READ THE EXTERNAL DATA
		$xml = file_get_contents($url);

		// MAKE AN OBJECT
		$obj = SimpleXML_Load_String($xml);

		// ACTIVATE THIS TO SEE THE OBJECT
		// var_dump($obj);

		// PROCESS THE OBJECT ELEMENTS INTO AN ARRAY
		$status = array();
		foreach ($obj->price as $thing)
		{
			array_push($status,(string)$thing);
		}

		// SHOW THE WORK PRODUCT
		print_r($status);
		//return $status;
	}
}

Open in new window


So as you can see, I'm using a print_r to see the result of my array.
But as my title says, its empty :(

Any ideas why?
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 35099490
Visit this URL in a regular web browser and use "view source" to see the XML:
http://eu.riftgame.com/en/status/eu-status.xml

As you will quickly see the <status> tag has <shard> tags with lots of attributes, but nowhere will you find a tag that would generate $obj->price as used on line 26 of the code snippet.
0
 
LVL 3

Author Comment

by:Mutsop
ID: 35099701
ooow.... this is kinda embaracing :(
This is what happens when you copy paste and dont check the code twice :)


thanks
0
 
LVL 3

Author Closing Comment

by:Mutsop
ID: 35099702
thanks
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 35101248
Thanks for the points and please don't feel bad about it - we've all done something like that!  All the best, ~Ray
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now