【问题标题】:Making a dynamic RSS feed from external XML file从外部 XML 文件制作动态 RSS 提要
【发布时间】:2013-10-19 20:59:50
【问题描述】:

我正在尝试为流式白标网站生成 RSS 提要。网络支持为我提供了有关如何生成任何内容的最基本信息。

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

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

所以,我已经设法通过搜索代码的 sn-p 来了解如何将实时信息从他们的 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>

这是附属网络提供的示例 sn-ps 之一,我可以看到它是我找到的上述代码的一部分:

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 提要 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 文件的数据(来自我在本文开头的第一个代码 sn-p)合并到一个 rss 提要 xml 文件中,但在链接中保留使用我的 whitelabel url。

更新

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

<?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 提要是否正确?我应该把它放在页面的哪个位置?

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

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

我想要的只是将我的原始代码变成一个 RSS 提要。我无法相信要找到相关信息有多么困难。

【问题讨论】:

  • 您好,不确定您所说的“我到目前为止尝试过什么”是什么意思?我已经在最初的帖子中解释了我在上面尝试过的所有内容。基本上我已经设法从一个远程 xml 文件生成一个 php 网页,但是我很难从该数据创建一个 RSS 提要。一切都在我的第一篇文章中进行了解释。任何建议都会受到极大的赞赏,因为我现在完全有货。谢谢。
  • 有人可以帮忙吗?我完全坚持这一点。
  • 我的意思是“到目前为止你尝试了什么?”正是这样。您尚未表明您已努力将 XML 提要返回的数据修改为 RSS 提要。您刚刚展示了如何获取原始提要并说您被卡住了。坚持什么?当您尝试解析初始 XML 结果并转换为 RSS 时,您遇到了什么具体问题?到目前为止,您所展示的只是您尝试基于原始 XML 提要输出 HTML。您尝试将其转换为 RSS 提要的代码在哪里?
  • 我试图在此处粘贴代码,但它说我超过了字符。我知道如何制作静态 RSS 提要,但我很难将我最初发布的代码合并到 rss 提要文档中。例如,Feed 将无法与 php 代码一起使用。
  • 这是一个基本的提要代码:网站提要 title> <description>网站 Feed 手动编码</description><link> <a href="/default/index/tourl?u=aHR0cDovL3d3dy55b3VyZG9tYWluLmNvbTwvbGluaw%3D%3D" rel="nofollow" target="_blank">yourdomain.com</link</a>> <item><title>特别活动 为我们的客户举办的关于我们产品的特别电话会议yourdomain.com/events.htm</link>

标签: php xml rss


【解决方案1】:

您希望将您的示例变成一个可用的 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 提要以使用特定服务预期的专有格式,您必须使用提要应采用的格式更新您的问题。您可以举一个您希望模拟的提要示例。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-23
    • 2011-07-16
    • 1970-01-01
    • 1970-01-01
    • 2013-04-02
    相关资源
    最近更新 更多