新版设计模式手册(C#)下载
最近不断的有朋友来Email问一些关于设计模式方面的问题,这更加坚定了我要把设计模式系列文章写完,也有朋友要一些示意性的代码,在我自己学习设计模式的过程中,个人认为http://www.dofactory.com/上面提供的一些例子还是不错的。为了大家学习的方便,我整理制作了这本新版设计模式手册(C#),算是为初学设计模式的朋友提供一点资料,希望能够对这些朋友有所帮助。手册共有150页左右,PDF格式,带有书签。包括了GOF23种经典设计模式,每一个模式都有结构图、生活例子、意图、适用性、示意性代码、实际运用代码等几个方面,多半都来自于网络,其中代码来自于http://www.dofactory.com/。
用XmlTextWriter类创建xml文件
2006年05月24日 11:28 上午 | 分类:Develop
原来在写xml时总是用StringBuilder的Append方法进行拼凑
现在的rss就是用xmlTextWriter类来实现
看具体的例子:
需要引用System.Text和System.Xml名称空间
StringBuilder sb = new StringBuilder();
using (XmlTextWriter xw = new XmlTextWriter(new StringWriter(sb)))
{
xw.WriteProcessingInstruction("xml", @"version=""1.0"" encoding=""utf-8""");
xw.WriteStartElement("rss");
xw.WriteAttributeString("version", "2.0");
xw.WriteStartElement("channel");
xw.WriteElementString("title", "幻想曲.Net");
xw.WriteElementString("description", "幻想曲.Net:专注于.Net技术!");
xw.WriteElementString("link", "http://www.yibin001.com");
xw.WriteElementString("language", "zh-cn");
xw.WriteElementString("generator", "www.yibin001.com");
xw.WriteElementString("WebMaster", "幻想曲.Net");
xw.WriteStartElement("image");
xw.WriteElementString("title", "幻想曲.Net - 专注于.Net技术");
xw.WriteElementString("url","http://www.yibin001.com");
xw.WriteElementString("logo", "http://www.yibin001.com/logo.gif");
xw.WriteEndElement();
string _strsql = "select top 15 documentid,subject,content,publishdate,categoryname from documents order by documentid desc";
using (SqlConnection conn = new SqlConnection(_connstr))
{
SqlCommand comm = new SqlCommand(_strsql, conn);
conn.Open();
using (SqlDataReader r = comm.ExecuteReader())
{
while (r.Read())
{
xw.WriteStartElement("item");
xw.WriteElementString("title", (string)r["subject"]);
xw.WriteElementString("link", "http://www.yibin001.com/zh-cn/item," + r["documentid"].ToString() + ".html");
xw.WriteElementString("category", r["categoryname"].ToString());
xw.WriteElementString("author", "幻想曲.Net");
xw.WriteElementString("pubdate", r["publishdate"].ToString());
xw.WriteElementString("guid", "http://www.yibin001.com/zh-cn/item," + r["documentid"].ToString() + ".html");
xw.WriteElementString("description", "");
xw.WriteEndElement();
}
}
}
xw.WriteEndElement();
xw.WriteEndElement();
}
具体的方法可参阅msdn文档,这里就不冗述了