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.
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.
Related
I have a soap request. I am able to send the request and get a response in a string. Now I want to convert it into XML and get the required data from it.
Response
string(1383) "
<?xml version="1.0" encoding="UTF-8"?>
<ResponseMessage xmlns:ns="http://iec.ch/TC57/2011/schema/message" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://iec.ch/TC57/2011/schema/message Message.xsd">
<Header>
<Verb>reply</Verb>
<Noun>EndDeviceControls</Noun>
<Revision>2.0</Revision>
<Timestamp>2019-05-04T10:39:11+04:30</Timestamp>
<Source>HES-BSTC</Source>
<AsyncReplyFlag>true</AsyncReplyFlag>
<ReplyAddress>http://ip:port/AmiWeb/services/Metering</ReplyAddress>
<User>
<UserID>user</UserID>
</User>
<MessageID>6C3F761B-A1EC-4EBE-BB49-67B720C5AE62</MessageID>
<CorrelationID>1001</CorrelationID>
<Property>
<Name>password</Name>
<Value>password</Value>
</Property>
<Property>
<Name>timeout(m)</Name>
<Value>30</Value>
</Property>
</Header>
<Reply>
<Result>OK</Result>
<Error>
<code>0.3</code>
</Error>
</Reply>
</ResponseMessage>"
Code
$xml_post_string = /** #lang text */
'<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soap="http://soap.inf.hexing.cn">
<soapenv:Header/>
<soapenv:Body>
<soap:doCommand>
<!--Optional:-->
<arg0><![CDATA[<?xml version="1.0" encoding="utf-8"?>
<RequestMessage
xmlns="http://iec.ch/TC57/2011/schema/message"
xmlns:m="http://iec.ch/TC57/2011/EndDeviceControls#"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://iec.ch/TC57/2011/schema/message Message.xsd">
<Header>
<Verb>create</Verb>
<Noun>EndDeviceControls</Noun>
<Revision>2.0</Revision>
<Timestamp>2016-01-01T00:00:00+04:30</Timestamp>
<Source>MDM</Source>
<AsyncReplyFlag>true</AsyncReplyFlag>
<ReplyAddress>http://ip:port/AmiWeb/services/Metering</ReplyAddress>
<AckRequired>true</AckRequired>
<User>
<UserID>'.$userName.'</UserID>
</User>
<MessageID>83c643e6-85c5-43c0-9e0a-fa1deb469b72</MessageID>
<CorrelationID>1001</CorrelationID>
<Property>
<Name>password</Name>
<Value>'.$password.'</Value>
</Property>
<Property>
<Name>timeout(m)</Name>
<Value>30</Value>
</Property>
</Header>
<Payload>
<m:EndDeviceControls>
<m:EndDeviceControl>
<m:reason>Disconnect/Reconnect</m:reason>
<m:EndDeviceControlType ref="3.0.211.23"/>
<m:EndDevices>
<m:mRID>'.$msn.'</m:mRID>
<m:Names>
<m:name>Disconnect</m:name>
<m:NameType>
<m:name>ControlType</m:name>
</m:NameType>
</m:Names>
</m:EndDevices>
</m:EndDeviceControl>
</m:EndDeviceControls>
</Payload>
</RequestMessage>
]]></arg0>
</soap:doCommand>
</soapenv:Body>
</soapenv:Envelope>';
$headers = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
//"SOAPAction: http://connecting.website.com/WSDL_Service/GetPrice",
"Content-length: ".strlen($xml_post_string),
); //SOAPAction: your op URL
$url = $soapUrl;
// PHP cURL for https connection
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP request
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// converting
$response = curl_exec($ch);
curl_close($ch);
$xml = simplexml_load_string($response);
var_dump($xml);
die();
Output
object(SimpleXMLElement)#121 (0) { }
The output is empty. Now I want two things
To convert string to XML
From the returned XML I want to get the value of <AsyncReplyFlag>true</AsyncReplyFlag> from the response
Update 1
As per suggestion, I have added below code
$xml = simplexml_load_string($response);
echo $xml->asXML();
Output
<?xml version="1.0" encoding="UTF-8"?>
<ResponseMessage xmlns:ns="http://iec.ch/TC57/2011/schema/message" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://iec.ch/TC57/2011/schema/message Message.xsd">
<Header>
<Verb>reply</Verb>
<Noun>EndDeviceControls</Noun>
<Revision>2.0</Revision>
<Timestamp>2019-05-04T14:01:48+04:30</Timestamp>
<Source>HES-BSTC</Source>
<AsyncReplyFlag>true</AsyncReplyFlag>
<ReplyAddress>http://ip:port/AmiWeb/services/Metering</ReplyAddress>
<User>
<UserID>user</UserID>
</User>
<MessageID>F4E15012-D009-4CBC-A610-E937F2620193</MessageID>
<CorrelationID>1001</CorrelationID>
<Property>
<Name>password</Name>
<Value>password</Value>
</Property>
<Property>
<Name>timeout(m)</Name>
<Value>30</Value>
</Property>
</Header>
<Reply>
<Result>OK</Result>
<Error>
<code>0.3</code>
</Error>
</Reply>
</ResponseMessage>
What I have tried?
$xml = new SimpleXMLElement($response);
print_r($xml);
die();
It gives me an empty result
$doc = new DOMDocument('1.0', 'utf-8');
$doc->loadXML($response);
$XMLresults = $doc->getElementsByTagName("AsyncReplyFlag")->item(0)->textContent;
echo $XMLresults;
die();
It gives me an error
Trying to get property of non-object
$XMLresults = $doc->getElementsByTagName("AsyncReplyFlag")->item(0)->textContent;
Still, I am unable to get the value of <AsyncReplyFlag>true</AsyncReplyFlag>
How can I achieve it?
Any help would be highly appreciated.
DOMDocument should have no problem extracting it, as a quick one-liner:
echo (#DOMDocument::loadXML($response))->getElementsByTagName("AsyncReplyFlag")->item(0)->textContent;
... or if you want to meticulously check for errors every step of the way,
$xml_errors=[];
set_error_handler(function(int $errno, string $errstr, string $errfile, int $errline, array $errcontext) use(&$xml_errors){
ob_start();
call_user_func_array('var_dump',func_get_args());
$xml_errors[]=ob_get_clean();
});
$domd=new DOMDocument();
$loaded=$domd->loadXML($response);
restore_error_handler();
if(!$loaded){
if(defined('STDERR')){
fprintf(STDERR,"%s",$response);
}
throw new \RuntimeException("errors parsing XML! xml printed in stderr, parsing errors: ".print_r($xml_errors,true));
}
$ele=$domd->getElementsByTagName("AsyncReplyFlag");
if($ele->length<1){
if(defined('STDERR')){
fprintf(STDERR,"%s",$response);
}
throw new \RuntimeException("did not get AsyncReplyFlag in response! (xml printed in stderr)");
}
echo $ele->item(0)->textContent;
Trying to output a SimpleXMLElement using var_dump() isn't a good idea and as you have seen - doesn't give much.
If you just want to see the XML it has loaded, instead use...
echo $xml->asXML();
which will show you the XML has loaded OK, so then to output the field your after is just
$xml = simplexml_load_string($response);
echo $xml->Header->AsyncReplyFlag;
Using the XPath query
$xml = new SimpleXMLElement($xmlData);
echo $xml->xpath('//AsyncReplyFlag')[0];
OR
You can use xml_parser_create
$p = xml_parser_create();
xml_parse_into_struct($p, $xml, $values, $indexes);// $xml containing the XML
xml_parser_free($p);
echo $values[12]['value'];
For other details, you can print_r($values)
This is full source code i am using with DCC where I replace merchantid and account with actual values
$merchantid = "merchantid"; $secret = "secret"; $account = 'account';
This is how i am creating hash
$tmp = "$timestamp.$merchantid.$orderid.$amountinCents.$currency.$cardnumber";
$md5hash = md5($tmp);
$tmp = "$md5hash.$secret";
$md5hash = md5($tmp);
below is the xml sending code
$xml = "<request type='auth' timestamp='$timestamp'>
<merchantid>$merchantid</merchantid>
<account>$account</account>
<orderid>$orderid</orderid>
<amount currency='$currency'>$amountinCents</amount>
<DCC_ENABLE>1</DCC_ENABLE>
<card>
<number>$cardnumber</number>
<expdate>$expdate</expdate>
<type>$cardtype</type>
<chname>$cardname</chname>
<cvn>
<number>$cvvno</number>
<presind>1</presind>
</cvn>
</card>
<dccinfo>
<ccp>euroconex</ccp>
<type>1</type>
<ratetype>S</ratetype>
<amount currency='$currency'>$amountinCents</amount>
</dccinfo>
<autosettle flag='1'/>
<md5hash>$md5hash</md5hash>
<tssinfo>
<address type=\"billing\">
<country>ie</country>
</address>
</tssinfo>
</request>";
// Send the request array to Realex Payments
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.realexpayments.com/epage-remote.cgi");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "payandshop.com php version 0.9");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); //This should always be set to 'TRUE' when in production to ensure the SSL is enabled.
$response = curl_exec ($ch);
curl_close ($ch);
$parseXML = simplexml_load_string($response);
echo "<pre>";print_r($parseXML);die();
it return me "320 An internal error has occured." message
i am not sure what i am doing wrong I want to add DCC facility.
Thanks for your question. Firstly, I would highly recommend you use the SHA1 algorithm to hash the transaction details instead of MD5.
Secondly, you didn't post your request XML but it must adhere to the following format:
<?xml version='1.0' encoding='UTF-8'?>
<request type='auth' timestamp='20171025141809'>
<merchantid>Merchant ID</merchantid>
<account>internet</account>
<channel>ECOM</channel>
<orderid>N6qsk4kYRZihmPrTXWYS6g</orderid>
<amount currency='EUR'>1001</amount>
<card>
<number>4263970000005262</number>
<expdate>0519</expdate>
<chname>James Mason</chname>
<type>VISA</type>
<cvn>
<number>123</number>
<presind>1</presind>
</cvn>
</card>
<autosettle flag='1'/>
<comments>
<comment id='1'>Mobile Channel</comment>
<comment id='2'>Down Payment</comment>
</comments>
<sha1hash>87707637a34ba651b6185718c863abc64b673f20</sha1hash>
</request>
Can you please ensure that you have the sha1hash element in the request XML and that it is being populated with the appropriate value.
Best,
Seán
Realex Payments
I have got XML response from curl and trying to search some tag value but I am failing. Kindly somebody help me
Please bare as I am new to the PHP
<?php
$DynamicValue = 'KWI';
$url='https://www.example.com/_api/web/lists/getbytitle(\'Stations\')/items?$select=OfficeId&$filter='.urlencode("CityCode eq '" . $DynamicValue . "'");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: application/xml"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$XML = new SimpleXMLElement($result);
foreach($XML->entry as $value)
{
echo $value->OfficeId
}
Output:
<?xml version="1.0" encoding="utf-8"?><feed xml:base="https://www.example.com/_api/" xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml"><id>a9f073a2-387e-4ac5-81b9-16b3ae81dba3</id><title /><updated>2017-03-20T08:15:47Z</updated><entry m:etag=""61""><id>Web/Lists(guid'5344b09b-d3f7-44ec-bd52-a8f5a99f23f9')/Items(23)</id><category term="SP.Data.StationsListItem" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /><link rel="edit" href="Web/Lists(guid'5344b09b-d3f7-44ec-bd52-a8f5a99f23f9')/Items(23)" /><title /><updated>2017-03-20T08:15:47Z</updated><author><name /></author><content type="application/xml"><m:properties><d:OfficeId>KWIKU08AA</d:OfficeId></m:properties></content></entry></feed>
Hope this will work.
$string='<?xml version="1.0" encoding="utf-8"?><feed xml:base="https://www.example.com/_api/" xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml"><id>a9f073a2-387e-4ac5-81b9-16b3ae81dba3</id><title /><updated>2017-03-20T08:15:47Z</updated><entry m:etag=""61""><id>Web/Lists(guid\'5344b09b-d3f7-44ec-bd52-a8f5a99f23f9\')/Items(23)</id><category term="SP.Data.StationsListItem" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /><link rel="edit" href="Web/Lists(guid\'5344b09b-d3f7-44ec-bd52-a8f5a99f23f9\')/Items(23)" /><title /><updated>2017-03-20T08:15:47Z</updated><author><name /></author><content type="application/xml"><m:properties><d:OfficeId>KWIKU08AA</d:OfficeId></m:properties></content></entry></feed>';
echo explode("</d:OfficeId>",explode("<d:OfficeId>", $string)[1])[0];
PHP Code demo
I am trying to make an RSS feed which feeds live data from a remote XML file provided to me for promoting a webcam network.
I want to run a feed within my official website. My problem is, I want to output the data into an RSS feed. I am not too familiar with RSS and php so there is a lot of guess work going on.
Here is the code I have so far which will not work, it incorporates php to retrieve the xml data. Also I am unsure as to what filename/type I save this as? XML or php? Both don't seem to work.
<?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>
?>
As you already have an XML source and want another XML result, maybe you could try XSLT to directly convert it.
http://www.w3schools.com/xsl/
I have been trying to upload video on video on you tube using my own code.
During one step when i try to upload videos meta data on you tube to get the token and url for the video to upload i get a
POST requests require a Content-length header. That’s all we know.
(411)
My code is as follows:
$xml = '<?xml version="1.0"?>
<entry xmlns="http://www.w3.org/2005/Atom"
xmlns:media="http://search.yahoo.com/mrss/"
xmlns:yt="http://gdata.youtube.com/schemas/2007">
<media:group>
<media:title type="plain">Video.loc</media:title>
<media:description type="plain">
Video.loc first vid
</media:description>
<media:category
scheme="http://gdata.youtube.com/schemas/2007/categories.cat">People
</media:category>
<media:keywords>Video.loc</media:keywords>
</media:group>
</entry>';
$headers = array('Authorization: AuthSub token="'.$_SESSION['AuthSubSessToken'],
'GData-Version: 2',
'X-GData-Key: key='.$key,
'Content-length:'.strlen($xml),
'Content-Type:application/atom+xml; charset=UTF-8'
);
$curl = curl_init('http://gdata.youtube.com/action/GetUploadToken');
curl_setopt($curl, CURLOPT_HTTPHEADER,$headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, $xml);
curl_setopt($curl, CURLOPT_HEADER, 0);
$response = simplexml_load_string(curl_exec($curl));
$response = curl_exec($curl);
$arrToken = explode('=',$response);
print('<pre>');print_r($arrToken);die();
curl_close($curl)
Does any one knows that if it is error on my side or on the google?.
Regards
Himanshu Sharma
You are missing a closing " after
AuthSub token="'.$_SESSION['AuthSubSessToken'],
that might be messing up the headers.