Showing posts with label xml. Show all posts
Showing posts with label xml. Show all posts

Tuesday, June 3, 2014

How to fetch Rss Feed Using Google api


Displaying RSS feeds easily using Google Ajax Feed API

Displaying RSS feeds from other sites (ie: CNN or Digg) on your own is a nice way to show constantly updated content automatically. However, for the novice web developer, setting this up can be daunting, requiring both knowledge from you and your server's ability to host remote files. Google's Ajax Feed API changes all that, by basically enabling any webmaster to display RSS feeds on their sites using some JavaScript code. It hosts the desired RSS feeds on their servers for you, caches them, and returns the data in either JSON or XML format for you to utilize. All that's left is for you to use some JavaScript to parse this data and output it on your page.
In this tutorial, I'll show you how to harness Google Ajax Feed API to fetch a RSS feed and display it on your site. Here are a few examples:
                                                                                   
/*








<script>
google.load("feeds""1");

// Our callback function, for when a feed is loaded.
function feedLoaded(result{
  if (!result.error{
    // Grab the container we will put the results into
    var container document.getElementById("content");
    container.innerHTML '';

    // Loop through the feeds, putting the titles onto the page.
    // Check out the result object for a list of properties returned in each entry.
    // http://code.google.com/apis/ajaxfeeds/documentation/reference.html#JSON
    for (var 0result.feed.entries.lengthi++{
      var entry result.feed.entries[i];
      var div document.createElement("div");
      div.appendChild(document.createTextNode(entry.title));
      container.appendChild(div);
    }
  }
}

function OnLoad({
  // Create a feed instance that will grab Digg's feed.
  var feed new google.feeds.Feed("http://www.digg.com/rss/index.xml");

  // Calling load sends the request off.  It requires a callback function.
  feed.load(feedLoaded);
}

google.setOnLoadCallback(OnLoad);
</script>

Wednesday, April 9, 2014

How to Fetch Data from RSS Using PHP


<style>
#data{
width:400px;

}
#data h2{
width:100%;
color:#1266ae;
padding:5px;
}
#data p{
border:1px solid #c6c6c6;
padding:5px;
}
#data p img{
width:100%;
}
</style>
<?php
// create a new DOMDocument object
$dom = new DOMDocument();
  //load a remote xml file
  $result = $dom->load("http://blog.lettersandlight.org/rss");
  //did the load work?
  if ($result) {
    //get an array of the items in the rss
    $items = $dom->getElementsByTagName('item');
    //loop through the array
    foreach($items as $item){
      //get the title of the current item
      $title = $item->getElementsByTagName('title')->item(0)->nodeValue;
      //get the description of the current item
      $desc = $item->getElementsByTagName('description')->item(0)->nodeValue;
      //output some of the collected data
 echo("<div id='data'>");
      echo "<h2> $title</h2><br>";
      echo "<p>$desc</p>";
 echo("</div>");
    }
  } else {
    echo "there was a problem reading the rss feed, bummer\n";
  }
?>

Wednesday, February 19, 2014

What Is Ajax How is work



  • AJAX stands for Asynchronous JavaScript and XML. AJAX is a new technique for creating better, faster, and more interactive web applications with the help of XML, HTML, CSS and Java Script.
  • Ajax uses XHTML for content and CSS for presentation, as well as the Document Object Model and JavaScript for dynamic content display.
  • Conventional web application trasmit information to and from the sever using synchronous requests. This means you fill out a form, hit submit, and get directed to a new page with new information from the server.
  • With AJAX when submit is pressed, JavaScript will make a request to the server, interpret the results and update the current screen. In the purest sense, the user would never know that anything was even transmitted to the server.
  • XML is commonly used as the format for receiving server data, although any format, including plain text, can be used.
  • AJAX is a web browser technology independent of web server software.
  • A user can continue to use the application while the client program requests information from the server in the background
  • Intuitive and natural user interaction. No clicking required only Mouse movement is a sufficient event trigger.
  • Data-driven as opposed to page-driven

Tuesday, February 18, 2014

How To generate RSS FEED USING PHP AND MYSQL


Basic structure of RSS feed.
<?xml version='1.0' encoding='UTF-8'?> 
<rss version='2.0'> 
<channel> 

<title>Website Title </title> 
<link>Website URL</link> 
<description>Website description</description> 
<language>en-us</language> 

<item> 
<title>Item/Article Title</title> 
<link>Item/Article URL </link> 
<description>Items/Article description </description> 
</item> 

</channel> 
</rss>

Sample Database Table.
CREATE TABLE site_data
(
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(250),
link VARCHAR(250),
description TEXT
);

rss.php
Code contains PHP and XML RSS basic structure tags. So your feed link http://domain.com/rss.php.
<?php
include('db.php');
$sql = "SELECT * FROM site_data ORDER BY id DESC LIMIT 20"; 
$query = mysql_query($sql) or die(mysql_error());

header("Content-type: text/xml"); 

echo "<?xml version='1.0' encoding='UTF-8'?> 
<rss version='2.0'>
<channel>
<title>9lessons | Programming Blog </title>
<link>http://9lessons.info</link>
<description>Programming Blog </description>
<language>en-us</language>"; 

while($row = mysql_fetch_array($query))
{
$title=$row['title']; 
$link=$row['link']; 
$description=$row['description']; 

echo "<item> 
<title>$title</title>
<link>$link</link>
<description>$description</description>
</item>"; 

echo "</channel></rss>"; 
?>

Structure Of RICH SITE SUMMARY (RSS)



<?xml version='1.0' encoding='UTF-8'?> 
<rss version='2.0'> 
<channel> 

<title>Website Title </title> 
<link>Website URL</link> 
<description>Website description</description> 
<language>en-us</language> 

<item> 
<title>Item/Article Title</title> 
<link>Item/Article URL </link> 
<description>Items/Article description </description> 
</item> 

</channel> 
</rss>

What Is XML

Extensible Markup Language (XML) is a markup language that defines a set of rules for encoding documents in a format that is both human-readable and machine-readable. It is defined in the XML 1.0 Specification[3] produced by the W3C, and several other related specifications, all free open standards.
The design goals of XML emphasize simplicity, generality, and usability over the Internet It is a textual data format with strong support via Unicode for the languages of the world. Although the design of XML focuses on documents, it is widely used for the representation of arbitrary data structures, for example in web services.
Many application programming interfaces (APIs) have been developed to aid software developers with processing XML data, and several schema systems exist to aid in the definition of XML-based languages.
As of 2009, hundreds of document formats using XML syntax have been developed, including RSS, Atom, SOAP, and XHTML. XML-based formats have become the default for many office-productivity tools, including Microsoft Office (Office Open XML), OpenOffice.org and LibreOffice (OpenDocument), and Apple's iWork. XML has also been employed as the base language for communication protocols, such as XMPP.


XML Declaration

<?xml version="1.0" encoding="UTF-8"?>


Tag

A markup construct that begins with < and ends with >. Tags come in three flavors:

  • start-tags; for example: <section>

  • end-tags; for example: </section>

  • empty-element tags; for example: <line-break />