drqvsx1228 2013-03-31 17:32 采纳率: 0%
浏览 28

如何制作Array2XML

I did this code where i try change tag <linkfoto></linkfoto> per tag <enclosure url="urlofpicturefromoriginalsite">

this rss is from rss uol

this my code '

<?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;
  }
   ?>'

but return a mass

 '<?xml version="1.0" encoding="ISO-8859-1"?>
  <rss version="2.0"><0><channel/><title/><description>Com a presença de milhares de fiéis, Francisco celebra no Vaticano a primeira missa da Ressurreição como papa</description><enclosure><@attributes><height>100</height><width>100</width><url/></@attributes></enclosure><date/></0><1><channel/><title/><description>Em resposta ao regime norte-coreano, Coreia do Sul fará manobras militares em conjunto com os EUA em abril</description><enclosure><@attributes><height>100</height><width>100</width><url/></@attributes></enclosure><date/></1></rss>'

and no some like that ` Internacional RSS DirectPoint pt-br

                <item>
                    <title>Internacional></title>


                    <description>Justiça eslovaca troca sentença de pena de morte ao agente nazista László Csatáry, 97, pela de prisão perpétua</description>


                                                <enclosure url="http://imguol.com/2012/07/18/18jul2012---o-criminoso-de-guerra-nazista-mais-procurado-do-mundo-o-hungaro-laszlo-csatary-97-deixou-a-procuradoria-de-budapeste-na-hungria-apos-o-ministerio-publico-ter-ordenado-a-sua-prisao-1342626431731_1024x768.jpg"  type="image/jpeg" width="1024" height="768"/>


                    <creditfoto><![CDATA[Bea Kallos/AP]]></creditfoto>
                    <pubdate>28/03/2013</pubdate>
                </item>


                <item>
                    <title><![CDATA[Internacional]]></title>


                    <description>Papa Francisco celebra missa em reformatório em Roma e lava pés de 12 detentos, incluindo uma jovem muçulmana></description>

                                                <enclosure url="http://imguol.com/2013/03/28/28mar2013---papa-francisco-beija-o-pe-de-jovem-detento-depois-de-lava-lo-durante-missa-no-presidio-de-casal-del-marmo-em-roma-o-papa-lavou-os-pes-de-12-detentos-incluindo-de-duas-garotas-1364498118757_1024x768.jpg"  type="image/jpeg" width="1024" height="768"/>

                    <creditfoto><![CDATA[Osservatore Romano/AFP]]></creditfoto>
                    <pubdate>28/03/2013</pubdate>
                </item>


</channel>
 </rss>

` Some one help me do works this ?

This is my first code :(

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?
    • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
    • ¥15 cmd cl 0x000007b
    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line