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);
            }


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

  • 相关阅读:
    trackr: An AngularJS app with a Java 8 backend – Part III
    trackr: An AngularJS app with a Java 8 backend – Part II
    21. Wireless tools (无线工具 5个)
    20. Web proxies (网页代理 4个)
    19. Rootkit detectors (隐形工具包检测器 5个)
    18. Fuzzers (模糊测试器 4个)
    16. Antimalware (反病毒 3个)
    17. Debuggers (调试器 5个)
    15. Password auditing (密码审核 12个)
    14. Encryption tools (加密工具 8个)
  • 原文地址:https://www.cnblogs.com/wzg0319/p/1398574.html
Copyright © 2011-2022 走看看