问题描述
最近完成了一些简单的rss资源读取但下面这个情况让我以后-<title>-疤痕修复:忘记不愉快的往事</title>(这种能正常的读取内容)-<title>-<![CDATA[疤痕修复:忘记不愉快的往事]]></title>==============================(这种读取出来就是空的了)我的读取操作如下:先读取到节点title,然后取节点的值用的“InnerText"麻烦那位大哥清楚的给一些指点谢谢
解决方案
解决方案二:
该回复于2008-05-20 12:29:14被版主删除
解决方案三:
XPATH??不行哦你看我的嘛doc.Load(RssUrl);XmlNodeListnodelist=doc.GetElementsByTagName("item");XmlNodeListobjItems1;inti=0;if(doc.HasChildNodes){foreach(XmlNodenodeinnodelist){stringtitle="";stringlink="";i+=1;if(node.HasChildNodes){objItems1=node.ChildNodes;foreach(XmlNodenode1inobjItems1){switch(node1.Name){case"title":title=node1.InnerText;break;case"link":link=node1.InnerText;break;}if(title!=""&&link!="")break;}Rss+="<ahref='"+link+"'target='_blank'>"+title+"</a><br>";}
解决方案四:
up一下
解决方案五:
????
解决方案六:
我改了一下,读取成功,你试一下:rss.xml<?xmlversion="1.0"encoding="utf-8"?><item><title><![CDATA[疤痕修复:忘记不愉快的往事]]></title></item>
xml.aspx<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="xml.aspx.cs"Inherits="xml"%><!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><headrunat="server"><title>无标题页</title></head><body><formid="form1"runat="server"><div></div></form></body></html>
xml.aspx.cs:usingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Collections;usingSystem.Web;usingSystem.Web.Security;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Web.UI.WebControls.WebParts;usingSystem.Web.UI.HtmlControls;usingSystem.Xml;publicpartialclassxml:System.Web.UI.Page{protectedvoidPage_Load(objectsender,EventArgse){XmlDocumentdoc=newXmlDocument();stringRss=string.Empty;doc.Load(Server.MapPath("xml.xml"));XmlNodeListnodelist=doc.GetElementsByTagName("item");XmlNodeListobjItems1;inti=0;if(doc.HasChildNodes){foreach(XmlNodenodeinnodelist){stringtitle="";stringlink="";i+=1;if(node.HasChildNodes){objItems1=node.ChildNodes;foreach(XmlNodenode1inobjItems1){switch(node1.Name){case"title":title=node1.InnerText;break;case"link":link=node1.InnerText;break;}if(title!=""&&link!="")break;}Rss+="<ahref='"+link+"'target='_blank'>"+title+"</a><br>";}}}Response.Write(Rss);}}