扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:ghost 来源:CSDN 2007年9月24日
关键字: ghost XmlTextWriter 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.WriteStartElement("Intro"); //最后效果:<Intro><![CDATA[相关内容]]></Intro>
w.WriteCData(myPoints[j].Intro);
w.WriteEndElement();
w.WriteEndElement();
w.WriteEndElement();
w.WriteEndDocument();
w.Close(); //完成xml文件的输出,关闭
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1729562
濡傛灉鎮ㄩ潪甯歌揩鍒囩殑鎯充簡瑙T棰嗗煙鏈€鏂颁骇鍝佷笌鎶€鏈俊鎭紝閭d箞璁㈤槄鑷抽《缃戞妧鏈偖浠跺皢鏄偍鐨勬渶浣抽€斿緞涔嬩竴銆�