zoukankan      html  css  js  c++  java
  • 修改XML文件

     修改XML文件里节点中的内容:

    XmlDocument xmlDoc = new XmlDocument();
            string path = Server.MapPath("~/xml/shopCityXml/2shopCity.xml");
            if (System.IO.File.Exists(path) == true)
            {

                xmlDoc.Load(path);
                XmlNodeList nodeList = xmlDoc.SelectSingleNode("adXMLPath").ChildNodes;//获取bookstore节点的所有子节点
                string ID = "";
                string type = "";
                foreach (XmlNode xn in nodeList)//遍历所有子节点
                {

                    if (xn.Name == "adItem")
                    {
                        XmlElement xe = (XmlElement)xn;
                        XmlNodeList nls = xe.ChildNodes;//继续获取xe子节点的所有子节点
                        foreach (XmlNode xn1 in nls)//遍历
                        {
                            XmlElement xe2 = (XmlElement)xn1;//转换类型

                            if (xe2.Name == "ID")
                            {
                                ID = xe2.InnerText.ToString();
                            }
                            if (xe2.Name == "type")
                            {
                                type = xe2.InnerText.ToString();
                            }
                            if (ID == "1" && type == "slide")
                            {
                                if (xe2.Name == "title")
                                {
                                    xe2.InnerText = "";
                                    xe2.AppendChild(xmlDoc.CreateCDataSection(txtSuperMarketTitle.Text.ToString().Trim()));
                                }
                                if (xe2.Name == "url")
                                {
                                    xe2.InnerText = "";
                                    xe2.AppendChild(xmlDoc.CreateCDataSection(txtSuperMarketLinkUrl.Text.ToString().Trim()));
                                }
                                if (xe2.Name == "imgUrl")
                                {
                                    xe2.InnerText = "";
                                    if (upLoad1.M_upLoadError == "succes")
                                    {
                                        xe2.AppendChild(xmlDoc.CreateCDataSection(upLoad1.M_upLoadUrlAddress));
                                        if (upLoad1.M_oldUrlAddress != "" && upLoad1.M_oldUrlAddress != "../testImages/IM.jpg")
                                        {
                                            string ImageUrl = Server.MapPath(upLoad1.M_oldUrlAddress);
                                            File.Delete(ImageUrl);
                                        }
                                    }
                                    else
                                    {
                                        xe2.AppendChild(xmlDoc.CreateCDataSection(upLoad1.M_oldUrlAddress));
                                    }
                                }
                                if (xe2.Name == "directions")
                                {
                                    xe2.InnerText = "";
                                    xe2.AppendChild(xmlDoc.CreateCDataSection(txtDescription.Text.ToString().Trim()));

                                    break;
                                }
                            }
                        }

                    }


                }
                FileInfo fi = new FileInfo(path);
                if (fi.Attributes.ToString().IndexOf("ReadOnly") != -1)
                {
                    fi.Attributes = FileAttributes.Normal;
                }
                xmlDoc.Save(path);
            }


       本人博客的文章大部分来自网络转载,因为时间的关系,没有写明转载出处和作者。所以在些郑重的说明:文章只限交流,版权归作者。谢谢

  • 相关阅读:
    应用Dubbo框架打造仿猫眼项目 理解微服务核心思想
    慕课网--docker走进第一个javaweb应用
    金融行业微服务架构解析-转载炼数成金架构模块金融行业微服务架构解析
    StringEscapeUtils防止xss攻击详解
    尚硅谷 dubbo学习视频
    【面试篇】寒冬求职之你必须要懂的Web安全
    echo "" > 和 echo "" >> 的区别
    python函数、模块、包
    python学习笔记(7)--循环语句
    python学习笔记(6)--条件分支语句
  • 原文地址:https://www.cnblogs.com/wzg0319/p/1398574.html
Copyright © 2011-2022 走看看