Showing posts with label xml. Show all posts
Showing posts with label xml. Show all posts
0
Posted on 4:32 AM by prajeesh and filed under ,
In a previous post i have explained about calling a web service from javascript, please see this post to see calling a web service without parameters.
Suppose you have a web service that accepts user name and password and returns a value in XML format and you want to show the returned value in a webpage or a widget.

For example :

<?xml version="1.0" encoding="utf-8" ?>
<int xmlns="http://tempuri.org/">1</int>

You can use following code snippet to call a web service from javascript:
<script language="text/javascript">
var returned_data;
var request = new XMLHttpRequest();
//function to initialize web service
function initializeWebservice()
{
var url="http://2test.hopto.org/Leadservice.asmx/GetLeadCounts?UserName=Prajeesh&Password=123456";; //Web service url
request.onreadystatechange = webStatusProc;
request.open( "GET", url, true );
request.send();
}
//function to process webservice response
function webStatusProc()
{
if (request.readyState == 4) // Request completed?
{
response = request.responseXML.toXML();
XML = XMLDOM.parse( response);
returned_data= XML.evaluate('string(/int)');
alert(returned-data);
//do anything with returned data
}
}
</script> Shout it kick it on DotNetKicks.com
2
Posted on 8:23 AM by prajeesh and filed under , , ,

RSS feeds or "Rich Site Summery" are XML documents that used to publish freequently updated works, and RSS document or Web feed includes full summerized text and meta data RSS is also known as "Really Simple Syndication". For detailed information regarding RSS Feeds visit here http://en.wikipedia.org/wiki/RSS_(file_format.
Sample RSS File


<?xml version="1.0" encoding="ISO-8859-1" ?>
<rss version="0.91">
<channel>
<title>Prajeesh's ASP.net Tech blog</title>
<link>http://www.prajeeshkk.blogspot.com</link>
<description>Web development help - By Prajeeesh </description>
<language>en-us</language>
<image>
<title>Prajeesh's Blog</title>
<url>http://www.prajeeshkk.blogspot.com/</url>
<link>http://www.prajeeshkk.blogspot.com/</link>
<width>90</width>
<height>36</height>
</image>
<item>
<title>Attack Update</title>
<link>http://www.prajeeshkk.blogspot.com/</link>
<description>
This is a test content for my test RSS document:My blog contains posts based on Web development, Web design , ASP.net development, javascript, HTML and CSS
By Prajeesh, October 22, 2008
</description>
</item>
<item>
<title>Test Post Second.ca</title>
<link>http://www.prajeeshkk.blogspot.com/</link>
<description>
This is another post content for testing RSS feeds
By Prajeesh, October 22, 2008
</description>
</item>
</channel>
</rss>

Creatting an RSS Feed using asp.net with C#
Step 1
Create a class clsRss and copy following code in the class.
using System;using System.Data;
using
System.Configuration;
using
System.Web;
using
System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml;
using System.Data.SqlClient;
using System.Text;
/// <summary>/// Summary description for clsRss

///
</summary>public class clsRss

{

clsArticle ObjArticle = new clsArticle();
public clsRss()
{

//
// TODO: Add constructor logic here//
}
public void CreateRss_Recent()
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "text/xml";XmlTextWriter objX = new XmlTextWriter(HttpContext.Current.Response.OutputStream, Encoding.UTF8);objX.WriteStartDocument();
objX.WriteStartElement("rss");
objX.WriteAttributeString("version","2.0");
objX.WriteStartElement("channel");
objX.WriteElementString("title", "prajeesh's Tech blog- Recent articles ");
objX.WriteElementString("link",http://www.testsite.com/rss.aspx);
objX.WriteElementString("description","Latest articles from your site .");objX.WriteElementString("copyright","(c) 2008, Your web solutions. All rights reserved.");
objX.WriteElementString("ttl","5");//
// Suppose Article_Recent_Rss() is a function that returns data table with columns Title,Description,link & Pubdate
//
DataTableReader objReader = ObjArticle.Artilce_Recent_Rss().CreateDataReader();
while (objReader.Read()){
objX.WriteStartElement("item");
objX.WriteElementString("title",objReader["Title"].ToString());
objX.WriteElementString("description",objReader["Summery"].ToString());
objX.WriteElementString("link",objReader["articleurl"].ToString() );
objX.WriteElementString("pubDate",objReader["Postdate"].ToString() );
objX.WriteEndElement();
}objReader.Close();
objX.WriteEndElement();
objX.WriteEndElement();
objX.WriteEndDocument();
objX.Flush();
objX.Close();
HttpContext.Current.Response.End();
}
}Step 2
in the page load event of feeds page, write the following code.
public partial class rss : System.Web.UI.Page
{
clsRss ObjRss = new clsRss();
protected void Page_Load(object sender, EventArgs e){
ObjRss.CreateRss_Recent(); }} Shout it kick it on DotNetKicks.com