从远程xml数据生成RSS源

时间:2013-10-18 15:51:12

标签: php xml curl rss

我正在尝试制作一个RSS源,它从提供给我的远程XML文件中提供实时数据,以推广网络摄像头网络。

我想在我的官方网站上运行Feed。我的问题是,我想将数据输出到RSS提要。我对RSS和php不太熟悉,所以有很多猜测工作正在进行中。

这是我到目前为止无法使用的代码,它结合了php来检索xml数据。另外我不确定我保存的文件名/类型是什么? XML还是php?两者似乎都不起作用。

<?php
$curlData = '<?xml version="1.0" encoding="UTF-8"?>
<SMLQuery>
<Options MaxResults="20"/>
<AvailablePerformers Exact="false" PageNum="1" CountTotalResults="true">
<Include>
<Country/>
<Headline/>
<Descriptions></Descriptions>
<Rating/>
<Age/>
<Gender/>
<Media>biopic</Media>
<FreeChatSort/>
<PerformanceSort/>
</Include>
<Constraints> <StreamType>live,recorded,offline</StreamType>
<PublicProfile/>
<Name></Name><NoKeywords/>
<RelativeURLs/>
<NoKeywords/>
</Constraints>
</AvailablePerformers>
</SMLQuery>';
$url='http://affiliate.streamate.com/?????/SMLResult.xml';
$curl = curl_init();

curl_setopt ($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl,CURLOPT_TIMEOUT,120);
curl_setopt($curl,CURLOPT_HTTPHEADER,array (
'Content-Type: application/xml; charset=utf-8',
));
curl_setopt ($curl, CURLOPT_POST, 1);
curl_setopt ($curl, CURLOPT_POSTFIELDS, $curlData);

$result = curl_exec($curl);
curl_close ($curl);

$xml = simplexml_load_string ($result);
// $json = json_encode($xml);
// $array = json_decode($json,TRUE);


?>


<?xml version="1.0" encoding="utf-8"?> 
<rss version="2.0"> 
<channel> 
<title>Website Feed</title> 
    <description>Website Feed coded manually</description>
<link>yourdomain.com</link>; 

<?php
foreach ($xml->AvailablePerformers->Performer as $perf) {

<item> 
<title><php? echo ".$perf->attributes()->Name ."?></title> 
<description><php? echo " .$perf->Descriptions->About ."?></description> 
<link><php? echo "<a href='http://www.example.com        /cam/".$perf->attributes()->Name."    /?AFNO=X-0-XXXXXX-XXXXXX&UHNSMTY=XXX?></link> 
</item> 
</channel>
</rss>
?>

1 个答案:

答案 0 :(得分:-1)

由于您已经拥有XML源并希望获得其他XML结果,因此您可以尝试使用XSLT直接转换它。

http://www.w3schools.com/xsl/