zoukankan      html  css  js  c++  java
  • xml change

                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load("bookstore.xml");
                XmlNodeList nodeList = xmlDoc.SelectSingleNode("bookstore").ChildNodes;//获取bookstore节点的所有子节点  
                foreach (XmlNode xn in nodeList)//遍历所有子节点  
                {
                    XmlElement xe = (XmlElement)xn;//将子节点类型转换为XmlElement类型  
                    if (xe.GetAttribute("genre") == "红")//如果genre属性值为“红”  
                    {
                        xe.SetAttribute("genre", "update红");//则修改该属性为“update红”  
                        XmlNodeList nls = xe.ChildNodes;//继续获取xe子节点的所有子节点  
                        foreach (XmlNode xn1 in nls)//遍历  
                        {
                            XmlElement xe2 = (XmlElement)xn1;//转换类型  
                            if (xe2.Name == "author")//如果找到  
                            {
                                xe2.InnerText = "亚胜";//则修改  
                                break;//找到退出来就可以了  
                            }
                        }
                        break;
                    }
                }
                xmlDoc.Save("bookstore.xml");//保存。

  • 相关阅读:
    ActiveSync合作关系对话框的配置
    WINCE对象存储区(object store)
    Wince 隐藏TASKBAR的方法
    Wince输入法换肤换语言机制
    poj 3080 Blue Jeans 解题报告
    codeforces A. Vasily the Bear and Triangle 解题报告
    hdu 1050 Moving Tables 解题报告
    hdu 1113 Word Amalgamation 解题报告
    codeforces A. IQ Test 解题报告
    poj 1007 DNA Sorting 解题报告
  • 原文地址:https://www.cnblogs.com/greencolor/p/1637764.html
Copyright © 2011-2022 走看看