您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

使用XmlTextWriter生成XML文件

2025/2/6 12:04:38发布21次查看
项目兼容需要生成一系列的xml文件,总结了下xml文件的生成基本方式
xmltextwriter w = new xmltextwriter("c:\xml文件名.xml", encoding.unicode); //encoding.unicode为生成xml文件的编码格式,到时候合输出:<?xml version="1.0" encoding="utf-16"?> 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节点属性,最后效果:<spotlist xmlns:xsi="http:www.w3.org/2001/xmlschema-instance" xmlns:xsd="http:www.w3.org/2001/xmlschema">  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"); //最后效果:<intro><![cdata[相关内容]]></intro>  w.writecdata(mypoints[j].intro); w.writeendelement();  w.writeendelement(); w.writeendelement(); w.writeenddocument(); w.close(); //完成xml文件的输出,关闭
以上就是使用xmltextwriter生成xml文件的内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product