C#写xml文件并保存

来源:百度知道 编辑:UC知道 时间:2024/09/18 03:29:22
- <album name="album1">
- <Preview path="album1" extension="xpi" sizew="680" sizeh="474" totalpage="25">
- <Page id="0" text="封面" bgimg="fm.xpi" sizew="680" sizeh="474" totalphoto="2">
<Photo id="0" x="0" y="0" minw="5029" minh="3504" pwidth="680" pheight="474" img="hard_cover_color.xpi" />
<Photo id="1" x="138" y="117" minw="3155" minh="1925" pwidth="406" pheight="243" img="sampleS.xpi" />
</Page>
</Preview>
</album>

那位能帮忙用C#的两个类xmlDocument 和 xmlNode帮我写一下上面上面这个XML文挡.保存在(album文件夹中)
最好能注明每一句的解释.谢谢..请勿复制粘贴

using System;
using System.Xml;

namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
XmlDocument doc = new XmlDocument(); // 创建dom对象

XmlElement root = doc.CreateElement("album"); // 创建根节点album
root.SetAttribute("name", "album1"); // 设置属性
doc.AppendChild(root); // 加入到xml document

XmlElement preview = doc.CreateElement("Preview"); // 创建preview元素
preview.SetAttribute("path", "album1"); //
preview.SetAttribute("extension", "xpi"); //
preview.SetAttribute("sizew", "680"); // 设置属性
preview.SetAttribute("sizeh", "474"); //
preview.SetAttribute("totalpage", "25"); //
root.AppendChild(preview); // 添加到xml document

//下面一样,不一行行写解释了

XmlElement page = doc.CreateElement(&