繁体   English   中英

从远程xml数据生成RSS feed

[英]generating an RSS Feed from remote xml data

我正在尝试制作一个RSS feed,该feed从提供给我的远程XML文件中获取实时数据,以促进网络摄像头网络。

我想在我的官方网站上运行提要。 我的问题是,我想将数据输出到RSS feed中。 我对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>
?>

由于您已经拥有XML源并想要另一个XML结果,也许您可​​以尝试XSLT直接将其转换。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM