Solved

joomla xml parser module

Posted on 2011-03-08
5
931 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 109

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 109

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Move wordpress site 3 39
How to properly use session_regenerate_id when user logs in 7 40
MySql and Apache/PHP Error Reporting 2 28
tutorial for ebay api 3 34
There is a huge demand for CodeIgniter among the PHP web developers due to its dynamic features and benefits these days. It is one of most popular and agile open source PHP framework for creating robust web applications in PHP web development field.…
This script checks a path to see if a folder exists. If the folder does exist you will get output "The folder has previously been created. No action taken" If not it will create the folder. Then adds one user modify permission to the folder. It …
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

777 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