douzhuang2570 2013-10-11 17:25
浏览 132

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

I am trying to generate an RSS feed for a streamate whitelabel site. The network support have provided me with the bare minimum information on how to generate anything.

This is all they have provided to generate info about live performers:

"This query is used to retrieve information about performers. You will receive the information packaged into an XML document. Please send your XML request by HTTP POST to: http://affliate.streamate.com/??????/SMLResult.xml Be sure to send a “Content-type: text/xml” header as part of the HTTP request. You may replace streamate.com with a branded domain, if one is available to you, to have URLs returned with that same branded domain instead of streamate.com"

So, I have managed to find out how to pull live info from their XML feed into a php page, by searching for a snippet of code, but this is not an RSS feed that I can utilise (to feed into social networks, etc).

If anyone can please give me some pointers on how to utilise their XML file into an RSS feed which links to my own whitelabe domain (as they have half instructed above).

Below is the code I have found and used to generate the live info on a php page (I just wish it was an RSS feed).

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

and here is one of the example snippets that the affiliate network provided, which I can see is part of the above code I found:

XML Request Structure Example, Real World Generic

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

Thanks for any advice anyone can give me. I really want to learn how to do this.

I am aware that an RSS feed xml file looks like this:

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

But I am wanting to combine the data from the external xml file (from my first code snippet at the begining of this post) into an rss feed xml file, but retaining the use of my whitelabel url in the links.

UPDATE

Ok, I have tried merging some of the php code into an xml doc using an rss feed code structure, but obviously I am failing as I do not quite understand what I am doing here. I have searched google endlessly on this. Here is my attempt at merging the codes:

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

UPDATE 2

I have removed the print_r() as instructed and saved the following code as a php file, uploaded it, but all I am seeing is a blank white page. I dont know what to change re the header tag so can you explain where the header code should be and what I need to add/change please?

This is the code I now have, saved as a php file (or should it be an xml file? as I want it as an RSS feed, not a php webpage).

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

Just bumping this thread in hope someone can assist? Thanks.

UPDATE

ok I understand that I need to set the header content type. I have searched the web and found this:

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

Is this correct for an rss feed? Where exactly in the page do I put this?

Also yet in my original code pasted above there is already a bit of code relating to content type stating:

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

All I want is my original code to be an RSS Feed. I can't believe how difficult this is proving to find information on.

  • 写回答

1条回答 默认 最新

  • douzi8112 2015-04-09 23:58
    关注

    You want to turn your example into a usable RSS feed you can plug into your WL and other types of sites. This is very easy with what you had previously. As an example lets pretend you create a PHP page on the example domain below:

    hxxp://www.example.com/pull_xml.php

    Put inside it this content:

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

    When you load that page into your browser you will see that it is an XML feed suitable for filling up your WL. To create a specific RSS feed from the data to work with a proprietary format expected by a certain service you will have to update your question with what format the feed should take. You can give an example of a feed you wish to emulate.

    Also, you can change all URL's to your WL's URL structure by asking for the stream and substituting streamate.com with your whitelabel's domain.

    评论

报告相同问题?

悬赏问题

  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了
  • ¥15 python:excel数据写入多个对应word文档
  • ¥60 全一数分解素因子和素数循环节位数
  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图
  • ¥30 乘子法解约束最优化问题的matlab代码文件,最好有matlab代码文件
  • ¥15 写论文,需要数据支撑