login  Naam:   Wachtwoord: 
Registreer je!
 Forum

XML maken en uitlezen met simpleXML

Offline GroundZero - 20/03/2012 02:35 (laatste wijziging 20/03/2012 02:36)
Avatar van GroundZeroLid Beste,

ik probeer een XML te maken en uit te lezen, echter weergeeft hij alleen de 1e en de rest niet... wat doe ik verkeerd?

  1. <?php
  2. /*#########################
  3. TWITTER RSS FEEDER
  4. #########################*/
  5. $xml = '<?xml version="1.0" ?>
  6. <rss version="2.0">
  7. <channel>
  8. <title>abc</title>
  9. <description>abc xml lezen</description>
  10. <link>http://www.mijnsite.nl/customers/abc/</link>
  11. <copyright>mijnsite - test</copyright>
  12. <lastBuildDate>20-03-2012</lastBuildDate>';
  13.  
  14. $xml .= '<item>
  15. <title>Item 1</title>
  16. <description>Omschrijving 1</description>
  17. <link>http://www.mijnsite.nl/</link>
  18. <guid>http://www.mijnsite.nl/item1/</guid>
  19. <pubDate>20-03-2012</pubDate>
  20. </item>
  21. <item>
  22. <title>Item 2</title>
  23. <description>Omschrijving 2</description>
  24. <link>http://www.mijnsite.nl/</link>
  25. <guid>http://www.mijnsite.nl/item2/</guid>
  26. <pubDate>20-03-2012</pubDate>
  27. </item>
  28. <item>
  29. <title>Item 3</title>
  30. <description>Omschrijving 3</description>
  31. <link>http://www.mijnsite.nl/</link>
  32. <guid>http://www.mijnsite.nl/item3/</guid>
  33. <pubDate>20-03-2012</pubDate>
  34. </item>';
  35.  
  36.  
  37. $xml .= '</channel>
  38. </rss>';
  39.  
  40. if(!$file = new SimpleXMLElement($xml))
  41. {
  42. echo 'UNABLE TO LOAD XML';
  43. }
  44. else
  45. {
  46. $i = 0;
  47. foreach($file as $value)
  48. {
  49. echo $value->item[$i]->title.'<br />';
  50. $i++;
  51. }
  52. }
  53. ?>

1 antwoord

Gesponsorde links
Offline icemar - 20/03/2012 06:24
Avatar van icemar Lid Op deze manier werkt het wel
  1. <?php
  2. /*#########################
  3.   TWITTER RSS FEEDER
  4. #########################*/
  5.  
  6. // Aantal item to show
  7. $items = 4;
  8.  
  9. $xml = '<?xml version="1.0" ?>
  10. <rss version="2.0">
  11. <channel>
  12. <title>abc</title>
  13. <description>abc xml lezen</description>
  14. <link>http://www.mijnsite.nl/customers/abc/</link>
  15. <copyright>mijnsite - test</copyright>
  16. <lastBuildDate>20-03-2012</lastBuildDate>';
  17.  
  18. $xml .= '<item>
  19. <title>Item 1</title>
  20. <description>Omschrijving 1</description>
  21. <link>http://www.mijnsite.nl/</link>
  22. <guid>http://www.mijnsite.nl/item1/</guid>
  23. <pubDate>20-03-2012</pubDate>
  24. </item>
  25. <item>
  26. <title>Item 2</title>
  27. <description>Omschrijving 2</description>
  28. <link>http://www.mijnsite.nl/</link>
  29. <guid>http://www.mijnsite.nl/item2/</guid>
  30. <pubDate>20-03-2012</pubDate>
  31. </item>
  32. <item>
  33. <title>Item 3</title>
  34. <description>Omschrijving 3</description>
  35. <link>http://www.mijnsite.nl/</link>
  36. <guid>http://www.mijnsite.nl/item3/</guid>
  37. <pubDate>20-03-2012</pubDate>
  38. </item>';
  39.  
  40.  
  41. $xml .= '</channel>
  42. </rss>';
  43.  
  44. if(!$xml = new SimpleXMLElement($xml))
  45. {
  46. echo 'UNABLE TO LOAD XML';
  47. }
  48. else
  49. {
  50. for($i=0;$i<$items;$i+=1)
  51. {
  52. echo $xml->channel->item[$i]->title .'<br />';
  53. }
  54. }
  55. ?>


suc6 er mee
Gesponsorde links
Je moet ingelogd zijn om een reactie te kunnen posten.
Actieve forumberichten
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.225s