Tuesday, May 29, 2007

RSS News Feed Back Reader

Download Source - 44 KB

This sample indicate how to read RSS news feed back using PHP

Sample Code

<?php
require_once('rss/rss_fetch.inc');
error_reporting(E_ERROR);
$rss = fetch_rss ( "http://www.youtube.com/rss/global/top_viewed_today.rss" ) ;
$items = array_slice($rss->items, 0);
$news_feed = ''; 
foreach ($items as $item )
{
       $news_feed .= '' . $item['title'] .'<br>'. $item['link'].'<br>'.$item['summary'] . '<br>' ;
}
echo $news_feed;
?>

This sample uses MagpieRSS library which is attached with the source code and also can be downloaded from the following link
http://magpierss.sourceforge.net

XML Reader

Download Source - 8 KB

This sample indicate how to parse XML file using PHP

Sample Code

<?php
require_once("xmllib.php");
$menufilename= "SampleFile.Xml";
$xml =& new XmlLib_xmlParser($menufilename);
$doc =& $xml->getDocument();
$Maindoc=$doc->children[0];
//$arr = $Maindoc->children[$i]->toArray();
if ($Maindoc->hasChildren())
{
       foreach($Maindoc->children as $group)
      {
            echo'id : '.$group->attributes['id'].' Title :'.$group->attributes['title']."<br>";
           if ($group->hasChildren())
           {
                 foreach($group->children as $menuItem)
                {
                     echo'id : '.$menuItem->attributes['id'].' Title : '.$menuItem->attributes['title']."";
                } echo '<br>';
           }
     }
}
?>


Sunday, May 13, 2007

My First CodeSmith Template

Download source - 1 KB

Consider this template that will generate the output of an AssemblyInfo.cs file

<%@ Property Name="Author" Type="System.String" Description="Lead author of the project." %>
<%@ Property Name="Title" Type="System.String" Description="Title of the project." %>
<%@ Property Name="Description" Type="System.String" Description="Description of the project." %>
<%@ Property Name="Configuration" Type="System.String" Default="Debug" Description="Project configuration." %>
<%@ Property Name="Company" Type="System.String" Default="MegaUtilities, Inc." %>
<%@ Property Name="Product" Type="System.String" Description="Product Name." %>
<%@ Property Name="Version" Type="System.String" Default="1.0.*" Description=".NET assembly version." %>
<%@ Property Name="FileVersion" Type="System.String" Default="1.0" Description="Win32 file version." %>
using System.Reflection;
using System.Runtime.CompilerServices;
//
// Created: <%= DateTime.Now.ToLongDateString() %>
// Author : <%= Author %>
//
[assembly: AssemblyTitle("<%= Title %>")]
[assembly: AssemblyDescription("<%= Description %>")]
[assembly: AssemblyConfiguration("<%= Configuration %>")]
[assembly: AssemblyCompany("<%= Company %>")]
[assembly: AssemblyProduct("<%= Product %>")]
[assembly: AssemblyCopyright("Copyright (c) <%= DateTime.Now.Year.ToString() %> <%= Company %>")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("<%= Version %>")]
[assembly: AssemblyFileVersion("<%= FileVersion %>")]
[assembly: AssemblyDelaySign(true)]

You should notice three distinct types of code in the previous template

1.Content that will never change

CodeSmith treat any code written outside the tag

<%= %>

as a static content that will appear as it was written the output file

2.Content that can be automatically generated

Like the segment

<%= DateTime.Now.ToLongDateString() %>

This will print the date of creation the output file

3. Content that you will prompt the user for

Like the property

<%@ Property Name="FileVersion" Type="System.String" Default="1.0" Description="Win32 file version."%>

This property will prompt the user to enter the value of the FileVersion