Advertisements

General Musing

blaze your trail

Posts Tagged ‘xsl

Figuring out PHP DOMDocument and XSLTProcessor #php

with one comment

Although I calculate the period I’ve been programming in decades, I am a relative PHP newbie. I’m testing and playing with PHP and writing distributed services, yet it’s sometimes the simple knowledge that I’m missing. (How does this Object perform the function that I want.) So I’ve been playing with the XML Classes in PHP and modified so code from PHP + Twitter + Google Calendar + SMS
. The article is quite interesting, and I discovered the Zend Framework, which makes my life much easier. 🙂

<?php
// Define credentials for the Twitter account
define(‘TWITTER_CREDENTIALS’, ‘USERNAME:PASSWORD’);

// Set up CURL with the Twitter URL and some options
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, ‘http://twitter.com/statuses/friends_timeline.rss&#8217;);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

// Twitter uses HTTP authentication, so tell CURL to send our Twitter account de
tails
curl_setopt($ch, CURLOPT_USERPWD, TWITTER_CREDENTIALS);

// Execute the curl process and then close
$data = curl_exec($ch);
curl_close($ch);

// MY CHANGES START HERE:

// Load XML
$dom = new DOMDocument();
$dom->loadXML(print_r($data, true));

// Load XSL:
$filename = “rss.xsl”; // You can find an rss.xsl file lots of places.
$domxsl = new DOMDocument();
$domxsl->load($filename);
$xsltp = new XSLTProcessor();
$xsltp->importStylesheet($domxsl);

// Apply XSL to XML
$result = $xsltp->transformToXML($dom);

// Output XSL Transformed XML
print ($result);
?>

Technorati technorati tags: , , , ,

Advertisements

Written by Daniël W. Crompton (webhat)

October 17, 2008 at 11:45 am

Posted in programming

Tagged with , , , ,

Playing with Gnip (Proof of Concept)

with one comment

I mentioned Gnip before, and this afternoon I was browsing the API definition and wanted to see if I could add my own publisher.

First I wanted to see how the messages are polled, so I crafted a wget command to retrieve some example data:

wget -nv --http-user="*username*" --http-passwd="*password*"
https://s.gnipcentral.com/publishers/digg/activity/current.xml

Read the rest of this entry »

Written by Daniël W. Crompton (webhat)

July 10, 2008 at 7:55 pm

%d bloggers like this: