从外部XML文件制作动态RSS源

时间:2013-10-11 17:25:31

标签: php xml rss

我正在尝试为streamate whitelabel网站生成RSS Feed。网络支持为我提供了有关如何生成任何内容的最低限度信息。

这是他们为生成有关现场表演者的信息所提供的全部内容:

"此查询用于检索有关表演者的信息。 您将收到打包到XML文档中的信息。 请通过HTTP POST将您的XML请求发送到: http://affliate.streamate.com/??????/SMLResult.xml 请务必发送“Content-type:text / xml”标头作为HTTP请求的一部分。您 可以用品牌域名替换streamate.com,如果有的话,可以使用 使用相同品牌域而非streamate.com"

返回的网址

所以,我已经设法找到如何通过搜索代码片段将实时信息从他们的XML提要中提取到php页面,但这不是我可以利用的RSS提要(用于社交网络)等等。)

如果有人可以请给我一些关于如何将他们的XML文件用于链接到我自己的whitelabe域的RSS源的指示(正如他们上面已经指示了一半)。

下面是我找到并用于在php页面上生成实时信息的代码(我只希望它是一个RSS提要)。

<?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);

print_r ($result);
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Cam Testing Going On :)</title>
<link rel="stylesheet" type="text/css" href="streamstyle.css" />
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body id="home">

<?php
foreach ($xml->AvailablePerformers->Performer as $perf) {
    echo "<br />";
    echo "<p>";
    echo "<strong>Name: </strong>" .$perf->attributes()->Name ."<br />";
    echo "<a href='http://www.mywhitelabeldomain.com/cam/".$perf->attributes()->Name."/?AFNO=X-0-XXXXXX-XXXXXX&UHNSMTY=XXX' target='_blank'><img src='http://mywhitelabeldomain.com".$perf->Media->Pic->Thumb->attributes()->Src."' /></a><br />";
    echo "<strong>Age: </strong>" .$perf->attributes()->Age ."<br />";
    echo "<strong>About: </strong>" .$perf->attributes()->Headline ."<br />";
    echo "<strong>Description: </strong>" .$perf->Descriptions->About ."<br />";
    echo "<strong>StreamType: </strong>" .$perf->attributes()->StreamType ."<br />";
    echo "<p>";
    echo "<br />";
}
?>

</body>
</html>

这是联盟网络提供的示例代码段之一,我可以看到上面代码的一部分我找到了:

XML请求结构 例如,真实世界通用

<?xml version="1.0" encoding="UTF-8"?>
<SMLQuery>
<Options MaxResults="50" />
<AvailablePerformers QueryId=”MyGenericQuery”>
<Include>
<Descriptions />
<Media>staticbiopic</Media>
</Include>
<Constraints>
<PublicProfile />
<StreamType>live</StreamType>
</Constraints>
</AvailablePerformers>
</SMLQuery>

感谢任何人可以给我的建议。我真的想学习如何做到这一点。

我知道RSS feed xml文件如下所示:

<?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>; <item> <title>A Special Event</title> <description>A Special Teleconference for our customers about our products</description> <link>yourdomain.com/events.htm</link>; </item> </channel> </rss>

但是我想将外部xml文件中的数据(从我在本文开头的第一个代码片段)合并到rss feed xml文件中,但保留在链接中使用我的whitelabel url。

更新

好的,我尝试使用rss feed代码结构将一些php代码合并到xml doc中,但显然我失败了,因为我不太明白我在这里做什么。我已经无休止地搜索谷歌。这是我尝试合并代码:

<?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);

print_r ($result);
?>


<?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.mydomain.com/cam/".$perf->attributes()->Name."    /?AFNO=X-0-XXXXXX-XXXXXX&UHNSMTY=XXX?></link>; 
</item> 
</channel>
</rss>
?>

更新2

我按照指示删除了print_r()并将以下代码保存为php文件,上传了它,但我所看到的只是一个空白页面。我不知道要更改标题标记的内容,所以你能解释一下标题代码的位置以及我需要添加/更改的内容吗?

这是我现在拥有的代码,保存为php文件(或者它应该是一个xml文件?因为我希望它作为RSS提要,而不是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.mydomain.com/cam/".$perf->attributes()->Name."    /?AFNO=X-0-XXXXXX-XXXXXX&UHNSMTY=XXX?></link> 
</item> 
</channel>
</rss>
?>

只是碰到这个帖子希望有人可以提供帮助?感谢。

更新

好的我明白我需要设置标题内容类型。我在网上搜索过,发现了这个:

<?php
header("Content-type:rss/xml");
?>

对于RSS Feed是否正确?我在这个页面的确切位置?

此外,在我上面粘贴的原始代码中,已经有一些与内容类型相关的代码说明:

'Content-Type: application/xml; charset=utf-8',
));

我想要的只是我的原始代码作为RSS Feed。我无法相信这有助于找到相关信息。

1 个答案:

答案 0 :(得分:0)

您希望将您的示例转换为可用的RSS源,您可以将其插入WL和其他类型的站点。你以前的这个很容易。举个例子,假设您在下面的示例域中创建了一个PHP页面:

hxxp://www.example.com/pull_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);

echo $result;

?>

当您将该页面加载到浏览器中时,您将看到它是一个适合填充WL的XML提要。要从数据创建特定的RSS源以使用特定服务所需的专有格式,您必须使用Feed应采用的格式更新您的问题。您可以举例说明您希望模拟的Feed。

此外,您可以通过询问流并将streamate.com替换为您的whitelabel域来将所有网址更改为您的WL网址结构。

相关问题