Reputation: 63
I am writing a simple class to read XML file and store its elements inside separate variables. As i finished writting my class and start testing it I noticed that it does not return anything..?
My php code:
<?php
class feedXML{
//Declear Vars public $mysongs; public $title; public $artist; public $date; //Load XML file public function loadXML(){ $this->mysongs = simplexml_load_file('songs.xml'); } //Assign XML data to Vars public function setXMLdata(){ foreach($this->mysongs as $songinfo){ $this->title=$songinfo->title; $this->artist=$songinfo->artist; $this->date=$songinfo['dateplayed']; }//end foreach } //Return Title element public function getTitle(){ echo $this->title; } //Return Artist element public function getArtist(){ echo $this->artist; } //Return Date element public function getDate(){ echo $this->date; } }
$test = new feedXML(); $test->getDate();
XML file structure:
songs song - title - artist - song song - title - artist - song song - title - artist - song songs
I am trying to echo out the variables but nothing appear on the browser..?
Upvotes: 0
Views: 48
Reputation: 1375
The code you gave never reads or interacts with the XML file, therefore $date
is never set. You need to call your loadXML
and setXMLdata
functions.
Upvotes: 0