Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include 'Array2XML.php';
- $doc = new DOMDocument();
- $doc->load('http://www3.uol.com.br/xml/midiaindoor/internacional.xml');
- $arrFeeds = array();
- foreach ($doc->getElementsByTagName('item') as $node) {
- $itemRSS = array (
- 'channel' => $node->getElementsByTagName('channel')->nodeValue,
- 'title' => $node->getElementsByTagName('title')->nodeValue,
- 'description' => $node->getElementsByTagName('description')->item(0)->nodeValue,
- 'enclosure' => array(
- '@attributes' => array(
- 'height' => '100',
- 'width' => '100',
- 'url' => $node->getElementsByTagName('linkfoto')->nodeValue,
- )
- ),
- //'linkfoto' => $node->getElementsByTagName('linkfoto')->item(0)->nodeValue,
- //'enclosure' => array($node->getElementsByTagName('linkfoto')->item(0)->nodeValue),
- //'attributes' => array(
- //'url' => array($node->getElementsByTagName('linkfoto')->nodeValue),
- //'url' => array('@cdata' => $node->getElementsByTagName('linkfoto')->item(0)->nodeValue),
- //'type' => 'image-jpeg',
- //'width' => '1024',
- //'height' => '768'
- // )
- //),
- //'creditfoto' => $node->getElementsByTagName('linkfoto')->item(0)->nodeValue,
- 'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue
- );
- array_push($arrFeeds, $itemRSS);
- }
- $xml = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><rss version=\"2.0\"></rss>");
- array_to_xml($arrFeeds,$xml);
- $xml->asXML("testefile.xml");
- function array_to_xml(array $arr, SimpleXMLElement $xml)
- {
- foreach ($arr as $k => $v) {
- is_array($v)
- ? array_to_xml($v, $xml->addChild($k))
- : $xml->addChild($k, $v);
- }
- return $xml;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement