您的位置:首页 > 其它

XmlTextWriter类可以把XML写入一个流、文件或TextWriter对象中

2007-11-08 17:11 281 查看
private void button2_Click(object sender, System.EventArgs e)
{
string filename = "booknew.xml";
XmlTextWriter tw = new XmlTextWriter(filename,null);
tw.Formatting = Formatting.Indented;
tw.WriteStartDocument();

tw.WriteStartElement("book");
tw.WriteAttributeString("genre","Mystery");
tw.WriteAttributeString("publicationdate","2001");
tw.WriteAttributeString("ISBN","123456789");
tw.WriteElementString("title","Case of the Missing Cookie");
tw.WriteStartElement("author");
tw.WriteElementString("name","Cookie Monster");
tw.WriteEndElement();
tw.WriteElementString("price","9.99");

string ss="hello world";
tw.WriteStartElement("hello");
tw.WriteCData(ss);
tw.WriteEndElement();

tw.WriteStar
tw.WriteEndElement();
tw.WriteEndDocument();
tw.Flush();
tw.Close();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐