小弟近日得到一个FLASH文件,用显示前台首页的轮换广告图片,它的图片地址和链接地址是由一个XML文件控制的。
但我不知道如何让用户在后台进行修改后,用代码修改这个XML文件,见以下:
pic_data.xml,四个节点依次为ID,文字,图片地址,链接地址<?xml version="1.0" encoding="gb2312"?>
<pic_info>
  <pic>
    <pic_id>01</pic_id>
    <pic_name>产品一</pic_name>
    <pic_url>AD/01.JPG</pic_url>
    <page_url>AboutUs.aspx</page_url>
  </pic>
  <pic>
    <pic_id>02</pic_id>
    <pic_name>产品二</pic_name>
    <pic_url>AD/02.JPG</pic_url>
    <page_url>TradeIdea.aspx</page_url>
  </pic>
  <pic>
    <pic_id>03</pic_id>
    <pic_name>产品三</pic_name>
    <pic_url>AD/03.JPG</pic_url>
    <page_url>ContactMe.aspx</page_url>
  </pic></pic_info>
麻烦大家给个思路,或者直接贴上代码,谢谢。

解决方案 »

  1.   

    很简单,直接对xml进行操作,你搜索一下c#对xml的操作。
    还有一个方法,先在数据库中建一张表字段为pic_id,pic_name,picurl,page_url,把表读出来后填充到一个dataTable里,直接用这个datatable生成一个xml文档
      

  2.   

    修改XML
    XMLDocument doc=new XMLDocument();
    doc.Load("");
    XmlNodeList nodeList = doc.SelectSingleNode("pic_info").ChildNodes;
            foreach (XmlNode xn in nodeList)
            {
               XmlElement xe = (XmlElement)xn;
                if(xe.GetAttribute("pic_id") == "")
                {
                 xe.SetAttribute("", "");
              }
            }
    doc.Save(Server.MapPath(""));
      

  3.   

    if(xe.Name== "")
    {xe.InnerText="";}
      

  4.   

    XmlDocument 读取节点信息
    然后转回赋值
      

  5.   

    给你个例子FileInfo fileInfo = new FileInfo(Server.MapPath(PathStr) + "/Soft.xml");                if (!fileInfo.Exists)
                    {
                        XmlTextWriter xmlW = new XmlTextWriter(Server.MapPath(PathStr + "/Soft.xml"), Encoding.Default);
                        xmlW.WriteStartDocument(true);                    xmlW.WriteStartElement("Soft");
                        xmlW.WriteEndElement();                    xmlW.WriteEndDocument();
                        xmlW.Close();
                    }                XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.Load(Server.MapPath(PathStr + "/Soft.xml"));                XmlNode root = xmlDoc.SelectSingleNode("Soft"); //查找<Soft>                string SoftIntro = this.softIntro.Text;                if (this.btnUpload.Text == "更新")
                    {
                        string editindex = this.hid_index.Value;
                        if (editindex != "")
                        {
                            int Index = Convert.ToInt16(editindex);
                            string SoftName = DataGrid_Module.Items[Index - 1].Cells[7].Text;
                            XmlNode NodeChe = root.SelectSingleNode("descendant::Soft_Item[SoftName='" + SoftName + "']");                        XmlNode NodeCheCld0 = NodeChe.ChildNodes[0];//SoftName
                            NodeCheCld0.InnerText = this.TxtB_Name.Text.Trim();                        XmlNode NodeCheCld1 = NodeChe.ChildNodes[1];//SoftImg
                            if (fj1path != "")
                                NodeCheCld1.InnerText = "<img src='" + com.GetFilUrl(fj1path) + "' border='0'>";                        XmlNode NodeCheCld2 = NodeChe.ChildNodes[2];//SoftImgPath
                            if (fj1path != "")
                                NodeCheCld2.InnerText = fj1path;                        XmlNode NodeCheCld3 = NodeChe.ChildNodes[3];//SoftLink
                            NodeCheCld3.InnerText = this.TxtB_Add.Text.Trim();                        XmlNode NodeCheCld5 = NodeChe.ChildNodes[5];//SoftIntro
                            NodeCheCld5.InnerText = SoftIntro;                        xmlDoc.Save(Server.MapPath(PathStr + "/Soft.xml"));                        Response.Write("<script>alert('更新成功')</script>");
                            this.btnUpload.Text = "上传";
                        }
                    }
                    else
                    {
                        //查找是否有相同SoftName的Soft_Item节点
                        string SoftName = this.TxtB_Name.Text.Trim();
                        XmlNode SearchNode = root.SelectSingleNode("descendant::Soft_Item[SoftName='" + SoftName + "']");
                        if (SearchNode != null)
                        {
                            Response.Write("<script>alert('已经存在名为[" + SoftName + "]的软件!')</script>");
                            return;
                        }                    XmlElement xe1 = xmlDoc.CreateElement("Soft_Item"); //创建一个<Soft_Item>节点                    XmlElement xesub1 = xmlDoc.CreateElement("SoftName");
                        xesub1.InnerText = this.TxtB_Name.Text; //设置文本节点
                        xe1.AppendChild(xesub1); //添加到<Soft_Item>节点中                    XmlElement xesub2 = xmlDoc.CreateElement("SoftImg");
                        if (fj1path == "")
                            xesub2.InnerText = "";
                        else
                            xesub2.InnerText = "<img src='" + com.GetFilUrl(fj1path) + "' border='0'>";
                        xe1.AppendChild(xesub2);                    XmlElement xesub3 = xmlDoc.CreateElement("SoftImgPath");
                        xesub3.InnerText = fj1path;
                        xe1.AppendChild(xesub3);                    XmlElement xesub4 = xmlDoc.CreateElement("SoftLink");
                        xesub4.InnerText = this.TxtB_Add.Text;
                        xe1.AppendChild(xesub4);                    XmlElement xesub5 = xmlDoc.CreateElement("SoftDisTag");
                        xesub5.InnerText = "0";//0为不在首页显示,1为首页显示
                        xe1.AppendChild(xesub5);                    XmlElement xesub6 = xmlDoc.CreateElement("SoftIntro");
                        xesub6.InnerText = SoftIntro;
                        xe1.AppendChild(xesub6);                    root.AppendChild(xe1); //添加到<Soft>节点中                    xmlDoc.Save(Server.MapPath(PathStr + "/Soft.xml"));
                        Response.Write("<script>alert('添加成功')</script>");
                    }
      

  6.   

    请问怎么通过后台管理前台的广告位置的广告啊  前台和后台都需要怎么设置啊  可不可以不用数据库啊  前台是静态的 麻烦说的详细些 thanks