What are yahoo pipes and why should I care? Yahoo! Pipes is a web application from Yahoo! that provides a graphical user interface for building data mashups that aggregate web feeds, web pages, and other services, creating Web-based apps from various sources, and publishing those apps. The site works by letting users “pipe” information from different sources and then set up rules for how that content should be modified (e.g. filtering). A typical example is New York Times through Flickr, a pipe which takes The New York Times RSS feed and adds a photo from Flickr based on the keywords of each item. The site is currently in beta. – Wikipedia

SeaCloud9 Pipes Yahoo pipes is an excellent tool for remixing the web into the way your would prefer the web to be. You can use pipes to sort out information what kind of information? Just about anything that is out there and free. So this naturally can come in handy. For example maybe I want to find a video I can make a pipe to search multiple websites like college humor, metacafe, or youtube all at once. You could also create a pipe to find all the homes that are being foreclosed in a given area the uses are only limited to your own imagination. This information comes to the end user in a variety of formats like RSS, ATOM, or JSON. Yahoo Pipes is only one example of many MashUp tools currently available on the web. You can also create mashups from scratch using libraries like cURL etc..

In this tutorial I will show you how to create an RSS/JSON reader in both C# and actionscript 3 with Silverlight and Flex skins. Silverlight and Flash/Flex are both RIA technologies and this is a field that will be extremely useful as far as the future of web applications are concerned. These technologies allow developer to make desktop applications, mobile applications, and web applications so you can imagine how useful it truly is to be versed with utilizing these technologies. My reason for doing this tutorial is simple to have fun. One of the neat things that yahoo pipes allows you to do with Yahoo Pipes is sort the information based on criteria that is displayed on the query string so I also have one example where the user can search for a video etc.. by typing a query into the textbox and hitting search pretty easy. Both of the examples will be re-factored but all can be used with minor tweaking of the code and like I said I just wanted to have fun so you can feel free to download the exampls and do whatever you want with them. These are simple examples just to display how to use JSON w/ Yahoo Pipes. The C# code has references (using statements) that are not required. I simply haven’t had time to remove them I wanted to use Silverlight3 play with the 3D capabilities and themeing. I also need to place in a little regexp to clean up the search string that is sent to Yahoo Pipes for example a space would be %20 but hey you know I don’t want to give away everything now do I. Also the flex example will wreck if you click on too many tabs to begin with this is a known issue I plan on creating classes out of both that create the text area element and have getter and setter.

simpleRSS/JSON in Silverlight3

using System;
using System.Text;
using System.Json;
using System.Collections;
using System.Collections.Generic;
using System.ServiceModel.Syndication;
using System.Collections.ObjectModel;
using System.Text.RegularExpressions;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Data.Services.Client;
using System.Threading;
using System.Windows.Browser;
using System.IO;
using System.Windows.Controls.Theming;
using System.Runtime.Serialization.Json;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace myFeedReader
{
    public partial class Page : UserControl
    {
        public string myURL;
        public string pipeOut = "";
        public string pipeTitle = "";
        public string returnString = "";
        public string pipeLinkedUP;
        public SearchLocator model = new SearchLocator();
        public IAsyncResult asyncResult;
        public string myJSONText = "";
        public string SearchVideo_URL = "";
        public string myJSONOUT;
        public DataContractJsonSerializer json = new DataContractJsonSerializer(typeof(JsonFeed));
        WebClient client = new WebClient();
        public Page()
        {

            InitializeComponent();

            XDocument feedXML;
            feedXML = XDocument.Load("Feeds.xml");
            var feeds = from feed in feedXML.Descendants("Feed") where feed.Attribute("status") == null || feed.Attribute("status").Value != "disabled" select new FeedDefinition { Name = feed.Element("Name").Value, Url = feed.Element("Url").Value };
            foreach (var feed in feeds)
            {
                feed.Name.ToString();
                feed.Url.ToString();
            }
            ddlFeeds.ItemsSource = feeds;
            myURL = "http://feeds.wired.com/wired/index?format=xml";
            BuildJson("http://pipes.yahooapis.com/pipes/pipe.run?Search=adobe&_id=aE4GjZv63BGt4u90l7okhQ&_render=json", "1");
            // Make HTTP request to get feed
            WebClient client = new WebClient();
            client.OpenReadCompleted += new OpenReadCompletedEventHandler(client_OpenReadCompleted);
            client.OpenReadAsync(new Uri(myURL));
        }
        public void ResponseHandler(IAsyncResult asyncResult)
        {
            HttpWebRequest request = (HttpWebRequest)asyncResult.AsyncState;
            HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asyncResult);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                var jsonFeed = json.ReadObject(response.GetResponseStream()) as JsonFeed;
                PipeOutput mypipe = new PipeOutput();
                int HiNum = jsonFeed.value.items.Length - 2;
                for (int i = 0; i <= HiNum; i++)
                {
                    var item = jsonFeed.value.items[i];
                    if (item.description != null && item.title != null && item.link != null)
                    {

                        this.Dispatcher.BeginInvoke(delegate()
                        {
                            pipeOut = item.description.ToString();
                            pipeLinkedUP = item.link.ToString();
                            pipeTitle = item.title.ToString();
                            returnString = Regex.Replace(pipeOut as string, "<.*?>", "");
                            returnString = Regex.Replace(returnString, @"\n+\s+", "\n\n");
                            returnString = HttpUtility.HtmlDecode(returnString);
                            TextBlock myPipeText = new TextBlock();
                            HyperlinkButton myPipeLink1 = new HyperlinkButton();
                            myPipeText.Foreground = new SolidColorBrush(Colors.White);
                            myPipeLink1.Content = pipeTitle;
                            myPipeLink1.NavigateUri = new Uri(pipeLinkedUP);
                            myPipeLink1.VerticalAlignment = VerticalAlignment.Top;
                            myPipeLink1.HorizontalAlignment = HorizontalAlignment.Left;
                            myPipeLink1.TargetName = "_blank";
                            myPipeText.Width = 400;
                            myPipeText.VerticalAlignment = VerticalAlignment.Top;
                            myPipeText.HorizontalAlignment = HorizontalAlignment.Left;
                            myPipeText.MinHeight = 60;
                            myPipeText.MaxHeight = 1000;
                            myPipeText.Margin = new Thickness(0);
                            myPipeText.TextWrapping = TextWrapping.Wrap;
                            myPipeText.Text = returnString;
                            if (myJSONText == "1")
                            {
                                
                                pipeContent.Children.Add(myPipeLink1);
                                pipeContent.Children.Add(myPipeText);
                                txtLoader1.Visibility = Visibility.Collapsed;
                                scl1.Visibility = Visibility.Visible;
                                pipeContent.Visibility = Visibility.Visible;
                                pipeContent.MaxHeight = 300;
                                
                            }
                            if (myJSONText == "2")
                            {
                                pipeContent.Children.Add(myPipeLink1);
                                pipeContent.Children.Add(myPipeText);
                                txtLoader1.Visibility = Visibility.Collapsed;
                                scl1.Visibility = Visibility.Visible;
                                pipeContent.Visibility = Visibility.Visible;
                            }
                            if (myJSONText == "3")
                            {
                                pipeContent1.Children.Add(myPipeLink1);
                                pipeContent1.Children.Add(myPipeText);
                                txtLoader2.Visibility = Visibility.Collapsed;
                                scl2.Visibility = Visibility.Visible;
                                pipeContent1.Visibility = Visibility.Visible;
                                
                            }
                            if (myJSONText == "4")
                            {
                                pipeContent2.Children.Add(myPipeLink1);
                                pipeContent2.Children.Add(myPipeText);
                                txtLoader3.Visibility = Visibility.Collapsed;
                                scl3.Visibility = Visibility.Visible;
                                pipeContent2.Visibility = Visibility.Visible;
                                cnvVideo.Visibility = Visibility.Visible;
                                txtLoader4.Visibility = Visibility.Collapsed;
                                
                            }
                            if (myJSONText == "5")
                            {
                                txtLoader4.Visibility = Visibility.Collapsed;
                                cnvVideo.Visibility = Visibility.Visible;
                                pipeContent3.Children.Add(myPipeLink1);
                                pipeContent3.Children.Add(myPipeText);
                                pipeContent3.Visibility = Visibility.Visible;
                                videoContent.Visibility = Visibility.Visible;
                                txtLoader5.Visibility = Visibility.Collapsed;
                            }
                            
                        });
      
                    }
                }
                
            }
            //This is a hack that will be taken out later.
            if (myJSONText == "3")
            {
                BuildJson("http://pipes.yahooapis.com/pipes/pipe.run?Search=Rich%20Internet%20Applications&_id=aE4GjZv63BGt4u90l7okhQ&_render=json", "4");
                Console.WriteLine("I was executed");
            }
            if (myJSONText == "2")
            {
                BuildJson("http://pipes.yahooapis.com/pipes/pipe.run?Search=Rich%20Internet%20Applications&_id=aE4GjZv63BGt4u90l7okhQ&_render=json", "3");
            }
            if (myJSONText == "1")
            {
                BuildJson("http://pipes.yahooapis.com/pipes/pipe.run?Search=SilverLight&_id=aE4GjZv63BGt4u90l7okhQ&_render=json", "2");
            }
        }



        public class PipeResponse
        {
            public string myJSONOUT;
        }
        public void BuildJson(string myJSON, string test)
        {
            myJSONText = test;
            try
            {
                HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri(myJSON));
                Console.Write(myJSON);
                asyncResult = request.BeginGetResponse(new AsyncCallback(ResponseHandler), request);
            }
            catch(Exception e)
            {
                Console.Write(e);
            }
            
           
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            itemsList.Visibility = Visibility.Collapsed;
            itemContent.Visibility = Visibility.Collapsed;
            object myFeed = ddlFeeds.SelectedItem;
            FeedDefinition MyFeed = new FeedDefinition();
            MyFeed = myFeed as FeedDefinition;
            myURL = MyFeed.Url;
            // Make HTTP request to get feed
            WebClient client = new WebClient();
            client.OpenReadCompleted += new OpenReadCompletedEventHandler(client_OpenReadCompleted);
            client.OpenReadAsync(new Uri(myURL));
        }

        private void Button_ClickVideo(object sender, RoutedEventArgs e)
        {
            model.searchTerm = txtSearch.Text.ToString();
            SearchVideo_URL = "http://pipes.yahooapis.com/pipes/pipe.run?Search=" + model.searchTerm + "&_id=aE4GjZv63BGt4u90l7okhQ&_render=json";
            BuildJson(SearchVideo_URL, "5");
            txtLoader5.Visibility = Visibility.Visible;
        }

        void client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
        {
            if (e.Error == null)
            {
                // Load feed into SyndicationFeed
                XmlReader reader = XmlReader.Create(e.Result);
                SyndicationFeed feed = SyndicationFeed.Load(reader);
                // Set up databinding
                itemsList.DataContext = (feed as SyndicationFeed).Items;
                itemsList.Visibility = Visibility.Visible;
            }

        }

        private void itemsList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            itemContent.Visibility = Visibility.Visible;
            // Set up databinding for detail view
            itemContent.DataContext = (sender as ListBox).SelectedItem as SyndicationItem;
        }

    }

    // Helper classes to clean up and shape received data for UI databinding
    public class HtmlSanitizer : IValueConverter
    {

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            // Remove HTML tags and empty newlines and spaces
            string returnString = Regex.Replace(value as string, "<.*?>", "");
            returnString = Regex.Replace(returnString, @"\n+\s+", "\n\n");
            // Decode HTML entities
            returnString = HttpUtility.HtmlDecode(returnString);
            return returnString;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    public class LinkFormatter : IValueConverter
    {

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return ((Collection)value).FirstOrDefault().Uri;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    public class JsonFeed
    {
        public PipeResponseValue value { get; set; }

    }
    public class PipeResponseValue
    {
        public Pipe[] items;
    }
    public class Pipe
    {
        public string title { get; set; }
        public string link { get; set; }
        public string description { get; set; }
    }
    public class PipeOutput
    {
        public string output { get; set; }
        public object image { get; set; }
        public Uri pipeLink { get; set; }
        public object pipetitle { get; set; }
    }


}

simpleRSS/JSON in Flex

import mx.containers.HBox;
import SearchLocator;
import mx.core.Application;
import mx.utils.ObjectUtil;
import mx.rpc.events.ResultEvent;
import com.adobe.utils.XMLUtil;
import com.adobe.serialization.json.JSON;
import com.adobe.xml.syndication.rss.Item20;
import com.adobe.xml.syndication.rss.RSS20;
import nl.demonsters.debugger.MonsterDebugger;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.EventDispatcher;
import flash.events.SecurityErrorEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.navigateToURL;
import flash.net.URLRequestMethod;
Security.loadPolicyFile("http://life.brendonsmith.com/public/crossdomain.xml");
Security.loadPolicyFile("http://pipes.yahooapis.com/crossdomain.xml");
Security.loadPolicyFile("http://seacloud9.org/crossdomain.xml");
Security.allowInsecureDomain("*");
Security.allowDomain("*");
public var RSS_URL:String = new String("");
public var loader:URLLoader;	
public var loader1:URLLoader;
public var loader2:URLLoader;
public var window_id:String;
public var window_render:String;
public var outXML:XMLList;
public var rss:RSS20;
public var body:XMLList;
public var d:MonsterDebugger = new MonsterDebugger(this);	
public var check:int = 0;
public function init():void
{
	loaderMovContainer.visible = true;
	outputFieldContainer.visible = false;
	onXML('http://life.brendonsmith.com/feed', 'one');
	
	
}
public function onSearchVideo(p_event:MouseEvent=null):void
{
	RSS_URL = "http://pipes.yahooapis.com/pipes/pipe.run?Search=" + SearchLocator._instance.searchTerm + "&_id=aE4GjZv63BGt4u90l7okhQ&_render=json";
	trace(SearchLocator._instance.searchTerm + "Search Run");
	window_render = "four";
	loader1 = new URLLoader();
	window_id = window_render;
	var request:URLRequest = new URLRequest(RSS_URL);
	request.method = URLRequestMethod.GET;
	//load the feed data
	//listen for when the data loads	
	try
	{
	loader1.load(request);
	loader1.addEventListener(Event.COMPLETE, onDataJSON);
	//load the feed data
	
	}
	catch(e:Error)
	{
		trace("Error: " + e.message);
	}
	trace("Search Excuted");
}
public function onXML(RSS_URL:String, window_render:String):void
{
check = 1;
loader = new URLLoader();
window_id = window_render;
var request:URLRequest = new URLRequest(RSS_URL);
request.method = URLRequestMethod.GET;
 
//listen for when the data loads
	try
	{
	loader.addEventListener(Event.COMPLETE, onDataLoad);
	//load the feed data
	loader.load(request);
	}
	catch(e:Error)
	{
		trace("Error: " + e.message);
	}
}

public function onJSON(RSS_URL:String, window_render:String):void
{

loader1 = new URLLoader();
window_id = window_render;
var request:URLRequest = new URLRequest(RSS_URL);
request.method = URLRequestMethod.GET;
//load the feed data
//listen for when the data loads
	try
	{
	loader1.load(request);
	loader1.addEventListener(Event.COMPLETE, onDataJSON);
	//load the feed data
	}
	catch(e:Error)
	{
		trace("Error: " + e.message);
	}

}
 
//called once the data has loaded from the feed
public function onDataLoad(e:Event):void
{
//get the raw string data from the feed
var rawRSS:String = URLLoader(e.target).data;
//parse it as RSS
parseRSS(rawRSS);
}
public function onDataJSON(e:Event):void
{
	try
	{
	var rawJSON:Object = JSON.decode(loader1.data);
	parseJSON(rawJSON);
	//load the feed data
	}
	catch(e:Error)
	{
		trace("Error: " + e.message);
	}
//parse it as RSS
}
public function parseJSON(data1:Object):void
{
//parse the raw rss data
var Items:Object = data1;
var data:String;
//get all of the items within the feed
trace(Items.value.items);
var itemsJSON:Array = Items.value.items;
//loop through each item in the feed
var outXML:XMLList = new XMLList()
trace(itemsJSON);
for (var i:int = 0; i < itemsJSON.length; i++ )
{
		if (Items.value.items[i].title != null && Items.value.items[i].description != null && Items.value.items[i].link != null)
		{
		var itemTitle:String = Items.value.items[i].title.toString();
		var itemDescription:String = Items.value.items[i].description.toString();
		var itemLink:String = Items.value.items[i].link.toString();
		trace(itemLink); 
		trace(itemDescription);
		outXML += buildItemHTML(itemTitle, itemDescription, itemLink);
		}
}
	data = outXML.toXMLString();
	switch(String(window_id))
				{
					case 'one':
					outputField.htmlText  = data;
					break;
					case 'two':
					loaderMovContainer1.visible = false;
					model.visiblityOne = true;
					loaderMovContainer1.height = 0;
					loaderMovContainer1.width = 0;
					outputField1.htmlText  = data;
					break;
					case 'three':
					outputField2.htmlText  = data;
					break;
					case 'four':
					outputFieldVideoSearch.htmlText  = data;
					break;
				}
	
}
//parses RSS 2.0 feed and prints out the feed titles into
//the text area
public function parseRSS(data:String):void
{
//XMLSyndicationLibrary does not validate that the data contains valid
//XML, so you need to validate that the data is valid XML.
//We use the XMLUtil.isValidXML API from the corelib library.
//create RSS20 instance
var rss:RSS20 = new RSS20();
//parse the raw rss data
rss.parse(data);
//get all of the items within the feed
var items:Array = rss.items;
//loop through each item in the feed
var outXML:XMLList = new XMLList()
for each(var item:Item20 in items)
{
//print out the title of each item
		var itemTitle:String = item.title.toString();
		var itemDescription:String = item.description.toString();
		var itemLink:String = item.link.toString();
		trace(itemLink); 
		trace(itemDescription);
		outXML += buildItemHTML(itemTitle, itemDescription, itemLink);
}
	data = outXML.toXMLString();
	check = 0;
	switch(String(window_id))
				{
					case 'one':
					loaderMovContainer.visible = false;
					loaderMovContainer.height = 0;
					loaderMovContainer.width = 0;
					outputFieldContainer.visible = true;
					outputField.htmlText  = data;
					break;
					case 'two':
					outputField1.htmlText  = data;
					break;
					case 'three':
					loaderMovContainer2.visible = false;
					model.visiblityTwo = true;
					loaderMovContainer2.height = 0;
					loaderMovContainer.width = 0;
					outputField2.htmlText  = data;
					break;
				}
}
public function buildItemHTML(itemTitle:String, itemDescription:String, itemLink:String):XMLList
{
	if (itemTitle != null && itemDescription != null && itemLink != null)
	{
	default xml namespace = new Namespace();
	var body:XMLList = new XMLList();
	body += new XML("" + itemTitle + "");
	try
	{
	var p:XML = < description > { new XML("

" + itemDescription + "

") }; } catch (e:Error) { trace("Error: " + e.message); p = < description > { new XML("

" + "Their has been an error" + "

") }; } var link:XML = ; link.@href = itemLink; link.font.@color = "#990000"; link.font = "More..."; p.appendChild(link); body += p; trace(body); } return body; }

Live Examples
Flex JSON / RSS example using Yahoo Pipes
Silverlight JSON / RSS example using Yahoo Pipes

Download
Flex Example
Silverlight3 Example