blogjava's web log

blogjava's web log
...

读新浪博客示例[源代码下载]

            当然。只是个DEMO. 功能还是很简单。BUG  也不少。有兴趣你可以下载 自己再改改。
 界面:



阅读界面:


关键代码:

 public  static ArrayList read(string url, HttpWebRequest request, bool isFirst)
        
{
            Stream stream 
= null;
            Uri uri 
= new Uri(url);
            
switch (uri.Scheme)
            
{
                
case "file":
                    
break;
                
case "https":
                    
goto case "http";
                
case "http":
                    
if (request == null)
                        request 
= (HttpWebRequest)WebRequest.Create(uri);
                    
try
                    
{
                        HttpWebResponse response 
= (HttpWebResponse)request.GetResponse();
                        
try
                        
{
                            
if (response.ContentEncoding != "")
                        Encoding.GetEncoding(response.ContentEncoding);
                        }
                        
catch { }
                        stream 
= response.GetResponseStream();
                    }

                    
catch (WebException we)
                    
{
                    }

                    
break;
            }

            ArrayList list 
= null;
            
if (stream != null)
            
{
                RssSina rssSina 
= new RssSina(stream);

                list
= rssSina.Read(isFirst);
                rssSina.Close();
                                      }
            
return list;
           
        }







分析 新浪的RSS  就是用的这个方法了。
      /// <summary>
        
/// Read rss
        
/// </summary>
        
/// <returns></returns>

        public ArrayList Read(bool isFirst)
        
{
            
int i = 0;
            StringBuilder sb 
= new StringBuilder();
            
bool readData = false;
            
if (reader != null)
            
{
                
do
                
{
                    pushElement 
= true;
                    readData 
= reader.Read();
                    
string readerName = reader.Name.ToLower();
                    
switch (reader.NodeType)
                    
{
                  
                        
case XmlNodeType.Element:
                            
{
                                elementText 
= new StringBuilder();
                                
if (reader.IsEmptyElement)
                                    
break;
                                
if (pushElement)
                                    xmlNodeStack.Push(readerName);
                                
break;

                            }

                        
case XmlNodeType.EndElement:
                            
{
                                
if (xmlNodeStack.Count == 1)
                                    
break;
                                
string childElementName = (string)xmlNodeStack.Pop();
                                
string parentElementName = (string)xmlNodeStack.Peek();

                                
switch (childElementName)
                                
{
                                    
item classes
                                }

                                
switch (parentElementName)
                                
{
                                       
                                    
case "sns:a":
                                        
switch (childElementName)
                                        
{
                                            
case "sns:href":
                                                
if (isFirst)
                                                
{
                                                   
                                                    
if (!pageList.Contains(elementText.ToString()) && elementText.ToString().Length != 0)
                                                    
{
                                                        
                                                        pageList.Add(elementText.ToString());
                                                    }

                                                   
                                                }

                                                
break;
                                        }

                                        
break;
                                        

                                    
case "item":
                                        
switch (childElementName)
                                        
{
                                            
case "title":
                                               
// listTitle.Add(elementText.ToString());
                                                break;
                                            
case "link":
                                               linkList.Add(elementText.ToString());
                                                
break;
                                            
case "description":

                                                
break;
                                            
case "sns:pubDate":
                                                
break;

                                        }

                                        
break;
                                }


                                
break;

                            }

                            
case XmlNodeType.Text:
                            
{
                                elementText.Append(reader.Value);
                                
break;
                            }

                            
case XmlNodeType.CDATA:
                            
{
                                elementText.Append(reader.Value);
                                i
++;
                                
break;
                            }

                    }

                }

                
while (readData);
                
            }

            listCont.Add(linkList);
            
if(pageList.Count!=0)
                listCont.Add(pageList);
            
return listCont;
        }


详细 请下载源代码研究。。
地址
http://www.blogjava.net/Files/wujun/WjSinaArticlesDemo.rar

点击这里直接下载




posted on 2006-10-23 15:50 record java and net 阅读(693) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航:
 

导航

常用链接

留言簿(44)

新闻档案

2.动态语言

3.工具箱

9.文档教程

友情链接

搜索

最新评论