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

           当然。只是个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

点击这里直接下载
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值