从远程 XML 数据生成 RSS 源


generating an RSS Feed from remote xml data

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

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

由于您已经有一个 XML 源并且想要另一个 XML 结果,也许您可以尝试使用 XSLT 直接转换它。

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