drew7721 Posted June 3, 2010 Share Posted June 3, 2010 Hey! I'm trying to get a php code to read, mod and display information from an xml or RSS file.. and it's really more that a mess. Everyone told me it's easy but there must be something i'm doing wrong. First, the projet is to get Tv Shows news to display on a site. I got the api and RSS feeds form TVrage.com site and they update the xml contend daily, so all I need to do is to get the file and save it on my server for faster reading. (that I know how). Here is a sample of an rss file with the new shows that will play today : <?xml version="1.0"?> <channel> <title>TVrage</title> <link>http://www.tvrage.com/</link> <description>TVrage</description> <language>en-us</language> <pubDate>Thu, Jun 3 2010 11:23:56 PDT</pubDate> <ttl>60</ttl> <docs>http://blogs.law.harvard.edu/tech/rss</docs> <item> <title>08:00 pm</title> <link>http://www.tvrage.com</link> </item> <item> <title>- Good Eats (14x02)</title> <link>http://www.tvrage.com/Good_Eats</link> <description>Grillus Domesticus</description> </item> <item> <title>- So You Think You Can Dance (07x03)</title> <link>http://www.tvrage.com/So_You_Think_You_Can_Dance</link> <description>Auditions #5 and #6 / Vegas Callbacks, Part 1</description> </item> <item> <title>- My First Place (13x05)</title> <link>http://www.tvrage.com/shows/id-6829</link> <description>Buying a Home Sight Unseen</description> </item> <item> <title>- WWE Superstars (02x08)</title> <link>http://www.tvrage.com/shows/id-22359</link> <description>060310</description> </item> </channel> now I saved this file as today.xml on my server and it updates every 24 hours trough a php code fread() etc.. What I want to do is to only display the titles of the shows that will play today, no time, no description or link. Is there a way to do that? I'm sure there is, but i'm really new to this whole xml thing and I don't get it. I mean I have no problems to work with a MySql db but this, xml, my brain just does not process it! This is the piece of code I got so far from W3 schools : <?php $xml = simplexml_load_file("today.xml"); echo $xml->getName() . "<br />"; foreach($xml->children() as $child) { echo $child->getName() . ": " . $child . "<br />"; } ?> As you can see if you test it, it does not do quite what I want it to do. P.S. I'm not sure if I am in the right section of forum, sorry.. did not find any related articles to xml issues. Thank's in advance 4 your help. Quote Link to comment https://forums.phpfreaks.com/topic/203788-php-and-xml-is-this-the-right-forum/ Share on other sites More sharing options...
dabaR Posted June 3, 2010 Share Posted June 3, 2010 Hi there. Please read this: http://www.phpfreaks.com/forums/index.php/topic,300076.msg1420283.html#msg1420283 , play with modifying it to your need a bit, and ask again for help when you get stuck. Quote Link to comment https://forums.phpfreaks.com/topic/203788-php-and-xml-is-this-the-right-forum/#findComment-1067316 Share on other sites More sharing options...
ignace Posted June 3, 2010 Share Posted June 3, 2010 libxml_use_internal_errors(true); $dom = new DomDocument(); if ($dom->load('today.xml')) { $xpath = new DomXPath($dom); foreach ($xpath->query('//item/title') as $node) { echo $node->nodeValue, "<br>\n"; } } Quote Link to comment https://forums.phpfreaks.com/topic/203788-php-and-xml-is-this-the-right-forum/#findComment-1067332 Share on other sites More sharing options...
drew7721 Posted June 3, 2010 Author Share Posted June 3, 2010 nice! thx for the replys I'll test them out and get back to you asap! I hope this works! Quote Link to comment https://forums.phpfreaks.com/topic/203788-php-and-xml-is-this-the-right-forum/#findComment-1067389 Share on other sites More sharing options...
drew7721 Posted June 3, 2010 Author Share Posted June 3, 2010 hey ignace! tried your version and it works great! Is there a place where I can read more on the funcions you used there and if there are more xml functions I can use... hard to find some good techniques and examples.. thx. Quote Link to comment https://forums.phpfreaks.com/topic/203788-php-and-xml-is-this-the-right-forum/#findComment-1067394 Share on other sites More sharing options...
ignace Posted June 4, 2010 Share Posted June 4, 2010 http://www.php.net/manual/en/class.domdocument.php http://www.php.net/manual/en/class.domxpath.php In the left sidebar you can find more XML-related classes. You can learn XPath here: http://w3schools.com/xpath/default.asp Quote Link to comment https://forums.phpfreaks.com/topic/203788-php-and-xml-is-this-the-right-forum/#findComment-1067552 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.