Information:
Extreme novice
PHP 4
Problem:
Trying to pull information from XML file and change it into a different layout and output to a new XML file. There seems to be many 'simpleXML' solutions, but this doesn't seem to be available on the server with PHP 4.
Here is the XML before:
<?xml version="1.0" encoding="ISO-8859-1" ?><?xml-stylesheet title="XSL_formatting" type="text/xsl" href="/shared/bsp/xsl/rss/nolsol.xsl"?><rss version="2.0"><channel><title>BBC Sport | Football | Premiership | UK Edition</title><link>http://news.bbc.co.uk/go/rss/-/sport1/hi/football/eng_prem/default.stm</link><description>Visit BBC Sport for all the action as it happens - up-to-the-minute news, results, breaking news, video, audio and feature stories. BBC Sport covers the major events and all the professional football clubs in the UK, plus cricket, rugby, golf, tennis, motorsport and all the main world sports.</description><language>en-gb</language><lastBuildDate>Thu, 21 Sep 2006 09:01:35 GMT</lastBuildDate><copyright>Copyright: (C) British Broadcasting Corporation, see http://news.bbc.co.uk/sport1/hi/help/rss/4517815.stm for terms and conditions of reuse</copyright><docs>http://www.bbc.co.uk/syndication/</docs><ttl>15</ttl><image><title>BBC Sport</title><url>http://news.bbc.co.uk/sol/shared/img/sport_120x60.gif</url><link>http://news.bbc.co.uk/go/rss/-/sport1/hi/football/eng_prem/default.stm</link></image><item><title>Liverpool 2-0 Newcastle</title><description>Xabi Alonso scores a wonder goal and Dirk Kuyt gets his first for Liverpool as the Reds beat Newcastle.</description><link>http://news.bbc.co.uk/go/rss/-/sport1/hi/football/eng_prem/5351794.stm</link> <guid isPermaLink="false">http://news.bbc.co.uk/sport1/hi/football/eng_prem/5351794.stm</guid><pubDate>Wed, 20 Sep 2006 20:58:25 GMT</pubDate><category>Premiership</category></item><item><title>Pearce shrugs off pressure talk</title><description>Manchester City boss Stuart Pearce plays down job pressure as his side's dismal run continues.</description><link>http://news.bbc.co.uk/go/rss/-/sport1/hi/football/teams/m/man_city/5366420.stm</link> <guid isPermaLink="false">http://news.bbc.co.uk/sport1/hi/football/teams/m/man_city/5366420.stm</guid><pubDate>Thu, 21 Sep 2006 08:44:09 GMT</pubDate><category>Man City</category></item></channel></rss>
And here is some php code courtesy of miniXML I tried and some of it worked until I started trying to to pull the elements from the file and then got into a complete and utter mess:
/****Use the MiniXML library****/
require_once('minixml.inc.php');
/****Create a MiniXMLDoc object called footyDoc****/
$footyDoc = new MiniXMLDoc();
/****Put string from XML file into footyDoc****/
$footyDoc->fromFile('./footy.xml');
/****Start at root element of footyDoc****/
$rootEl =& $footyDoc->getRoot();
/****Verify and show what is in the footyDoc****/
print $footyDoc->toString();
/****Start getting the elements within the footyDoc XML file****/
$item =& $footyDoc->getElement('item');
/**** We can now use the ITEM element to get access to it's children.
$title =& $item->getElement('title');
$description =& $item->getElement('description');
$link =& $item->getElement('link');
/**************************************************
*I NOW NEED TO SORT THE ELEMENTS INTO A NEW LAYOUT AND POST THEM INTO A NEW XML FILE*
***************************************************/
Here is what I would like the final XML file to like like after I get the php code to work:
<items>
<item title="Liverpool 2-0 Newcastle" description="Xabi Alonso scores a wonder goal and Dirk Kuyt gets his first for Liverpool as the Reds beat Newcastle." url="http://news.bbc.co.uk/go/rss/-/sport1/hi/football/eng_prem/5351794.stm" /><item title="Pearce shrugs off pressure talk" description="Manchester City boss Stuart Pearce plays down job pressure as his side's dismal run continues." url="http://news.bbc.co.uk/go/rss/-/sport1/hi/football/teams/m/man_city/5366420.stm" />
</items>
Can anybody offer any advice why it's not working or suggest an easier method for changing the layout of the XML file. Sorry in advance if this has already done the rounds, but I have spent many hours searching these forums and enjoying the crash course on parsing XML files. Any advice or exmples would be appreciated in trying to resolve this issue.
Meantime I will continue my enlightenment by working on the second half of the php code and try to get the layout correct from the elements above.