国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

使用XmlTextWriter生成XML文件

2019-11-17 04:27:27
字體:
來源:轉載
供稿:網友
項目兼容需要生成一系列的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文件的輸出,關閉
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 策勒县| 奎屯市| 衡阳县| 新密市| 古蔺县| 舟曲县| 千阳县| 台前县| 吉木萨尔县| 南靖县| 寿宁县| 大埔区| 古丈县| 乌兰察布市| 黄龙县| 瑞昌市| 安阳市| 松滋市| 郁南县| 富顺县| 惠来县| 安陆市| 广德县| 杨浦区| 泊头市| 炉霍县| 鹰潭市| 高雄县| 南木林县| 汝南县| 亳州市| 道真| 翁源县| 阳城县| 阿克苏市| 龙游县| 宝清县| 敖汉旗| 礼泉县| 永安市| 兴海县|