扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者: 来源:中国软件网 2008年6月24日
关键字: 生成 XmlTextWriter 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.WriteStartElement("Intro"); //最后效果:
w.WriteCData(myPoints[j].Intro);
w.WriteEndElement();
w.WriteEndElement();
w.WriteEndElement();
w.WriteEndDocument();
w.Close(); //完成xml文件的输出,关闭
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。