栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 人工智能 > NLP

使用XmlTextWriter生成XML文件

NLP 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用XmlTextWriter生成XML文件

项目兼容需要生成一系列的xml文件,总结了下XML文件的生成基本方式

XmlTextWriter w = new XmlTextWriter("C:XML文件名.xml", Encoding.Unicode); //Encoding.Unicode为生成XML文件的编码格式,到时候合输出:w.Formatting = Formatting.Indented; // 这个比较重要,这个属性说明xml文件里面的内容是按级别缩进的。//下面开始生成文件的内容w.WriteStartdocument(); //开始写xml,在最后有一个与之匹配的w.WriteEnddocument();w.WriteStartElement("SpotList"); w.WriteAttributeString("xmlns:xsi", "http:www.w3.org/2001/XMLSchema-instance");  //SpotList节点的属性 w.WriteAttributeString("xmlns:xsd", "http:www.w3.org/2001/XMLSchema");  //SpotList节点属性,最后效果: w.WriteStartElement("Items");  w.WriteElementString("Name", myPoints[j].Name);  w.WriteElementString("Caption", myPoints[j].Caption);  w.WriteElementString("Addr", myPoints[j].Addr);  w.WriteElementString("Phone", myPoints[j].Phone);  w.WriteStartElement("Intro"); //最后效果:   w.WriteCData(myPoints[j].Intro);  w.WriteEndElement(); w.WriteEndElement();w.WriteEndElement();w.WriteEnddocument();w.Close(); //完成xml文件的输出,关闭

以上就是使用XmlTextWriter生成XML文件的内容,更多相关内容请关注PHP中文网(www.kaotop.com)!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/794868.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号