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

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

关键代码:

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

InBlock.gif                    
catch (WebException we)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
break;
ExpandedSubBlockEnd.gif            }

InBlock.gif            ArrayList list 
= null;
InBlock.gif            
if (stream != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
InBlock.gif                RssSina rssSina 
= new RssSina(stream);

InBlock.gif                list
= rssSina.Read(isFirst);
InBlock.gif                rssSina.Close();
InBlock.gif                   InBlock.gif       ExpandedSubBlockEnd.gif            }
InBlock.gif            
return list;
InBlock.gif           
ExpandedBlockEnd.gif        }







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

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

InBlock.gif                        
case XmlNodeType.EndElement:
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
{
InBlock.gif                                
if (xmlNodeStack.Count == 1)
InBlock.gif                                    
break;
InBlock.gif                                
string childElementName = (string)xmlNodeStack.Pop();
InBlock.gif                                
string parentElementName = (string)xmlNodeStack.Peek();
InBlock.gif
InBlock.gif                                
switch (childElementName)
ExpandedSubBlockStart.gifContractedSubBlock.gif                                
{
ContractedSubBlock.gifExpandedSubBlockStart.gif                                    
item classes#region item classes
InBlock.gif                                    
case "rss":
InBlock.gif                                        readData 
= false;
InBlock.gif                                        
break;
InBlock.gif                                    
case "channel": ;
InBlock.gif                                        readData 
= false;
InBlock.gif                                        
break;
ExpandedSubBlockEnd.gif                                    
#endregion

ExpandedSubBlockEnd.gif                                }

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

InBlock.gif                                                   
ExpandedSubBlockEnd.gif                                                }

InBlock.gif                                                
break;
ExpandedSubBlockEnd.gif                                        }

InBlock.gif                                        
break;
InBlock.gif                                        
InBlock.gif
InBlock.gif                                    
case "item":
InBlock.gif                                        
switch (childElementName)
ExpandedSubBlockStart.gifContractedSubBlock.gif                                        
dot.gif{
InBlock.gif                                            
case "title":
InBlock.gif                                               
// listTitle.Add(elementText.ToString());
InBlock.gif
                                                break;
InBlock.gif                                            
case "link":
InBlock.gif                                               linkList.Add(elementText.ToString());
InBlock.gif                                                
break;
InBlock.gif                                            
case "description":
InBlock.gif
InBlock.gif                                                
break;
InBlock.gif                                            
case "sns:pubDate":
InBlock.gif                                                
break;
InBlock.gif
ExpandedSubBlockEnd.gif                                        }

InBlock.gif                                        
break;
ExpandedSubBlockEnd.gif                                }

InBlock.gif
InBlock.gif                                
break;
InBlock.gif
ExpandedSubBlockEnd.gif                            }

InBlock.gif                            
case XmlNodeType.Text:
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
dot.gif{
InBlock.gif                                elementText.Append(reader.Value);
InBlock.gif                                
break;
ExpandedSubBlockEnd.gif                            }

InBlock.gif                            
case XmlNodeType.CDATA:
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
dot.gif{
InBlock.gif                                elementText.Append(reader.Value);
InBlock.gif                                i
++;
InBlock.gif                                
break;
ExpandedSubBlockEnd.gif                            }

ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

InBlock.gif                
while (readData);
InBlock.gif                
ExpandedSubBlockEnd.gif            }

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


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

点击这里直接下载




转载于:https://www.cnblogs.com/wujun/archive/2006/10/23/537348.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值