Advertisement
vonhellsing

mycode

Mar 31st, 2013
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.79 KB | None | 0 0
  1. <?php
  2.  
  3. include 'Array2XML.php';
  4. $doc = new DOMDocument();
  5. $doc->load('http://www3.uol.com.br/xml/midiaindoor/internacional.xml');
  6. $arrFeeds = array();
  7. foreach ($doc->getElementsByTagName('item') as $node) {
  8. $itemRSS = array (
  9.   'channel' => $node->getElementsByTagName('channel')->nodeValue,
  10.   'title' => $node->getElementsByTagName('title')->nodeValue,
  11.   'description' => $node->getElementsByTagName('description')->item(0)->nodeValue,
  12.    'enclosure' => array(
  13.             '@attributes' => array(
  14.                 'height' => '100',
  15.                 'width' => '100',
  16.                 'url' => $node->getElementsByTagName('linkfoto')->nodeValue,
  17.                
  18.             )
  19.             ),
  20.            
  21.   //'linkfoto' => $node->getElementsByTagName('linkfoto')->item(0)->nodeValue,
  22.   //'enclosure' => array($node->getElementsByTagName('linkfoto')->item(0)->nodeValue),
  23.                     //'attributes' => array(
  24.                     //'url' => array($node->getElementsByTagName('linkfoto')->nodeValue),
  25.                         //'url' => array('@cdata' => $node->getElementsByTagName('linkfoto')->item(0)->nodeValue),
  26.                         //'type' => 'image-jpeg',
  27.                         //'width' => '1024',
  28.                         //'height' => '768'
  29.                     //  )
  30.                      //),
  31.   //'creditfoto' => $node->getElementsByTagName('linkfoto')->item(0)->nodeValue,
  32.   'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue
  33.   );
  34. array_push($arrFeeds, $itemRSS);
  35. }
  36.  
  37. $xml = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><rss version=\"2.0\"></rss>");
  38.  
  39. array_to_xml($arrFeeds,$xml);
  40.  
  41. $xml->asXML("testefile.xml");
  42.  
  43.  
  44. function array_to_xml(array $arr, SimpleXMLElement $xml)
  45. {
  46.     foreach ($arr as $k => $v) {
  47.         is_array($v)
  48.             ? array_to_xml($v, $xml->addChild($k))
  49.             : $xml->addChild($k, $v);
  50.     }
  51.     return $xml;
  52. }
  53. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement