Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 970
  • Last Modified:

joomla xml parser module

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
Mutsop
Asked:
Mutsop
  • 3
  • 2
1 Solution
 
MutsopAuthor Commented:
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
 
Ray PaseurCommented:
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
 
MutsopAuthor Commented:
ooow.... this is kinda embaracing :(
This is what happens when you copy paste and dont check the code twice :)


thanks
0
 
MutsopAuthor Commented:
thanks
0
 
Ray PaseurCommented:
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now