918博天堂

Server : Microsoft-IIS/10.0
System : Windows NT EBS-6136 10.0 build 17763 (Windows Server 2016) i586
User : jxgj ( 0)
PHP Version : 7.0.33
Disable Function : passthru,exec,system,shell_exec,proc_open,popen,pcntl_exec,socket_bind,stream_socket_server
Directory :  D:/tmp_aspnet/root/bc799001/4fb1bdec/
Upload File :
Current Directory [ Writeable ] Root Directory [ Writeable ]


Current File : D:/tmp_aspnet/root/bc799001/4fb1bdec/App_Code.5zheqldi.2.cs
?#pragma checksum "D:\wwwroot\lmturbo\wwwroot\App_Code\XMLHelpers.cs" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "9889CC85D5DD20DE063C1E878AEF95D6324C1732"

#line 1 "D:\wwwroot\lmturbo\wwwroot\App_Code\XMLHelpers.cs"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml;

/// <summary>
/// XMLHelpers 的提要注明
/// </summary>
public class XMLHelpers
{
    ///<summary>
    /// XMLHelper XML文档操作治理器
    ///</summary>
    public XMLHelpers()
    {
        //
        // TODO: 在此处增长机关函数逻辑
        //
    }
    XmlDocument xmlDoc;
    ///<summary>
    /// 插入节点
    ///</summary>
    public void InsertNode(string xmlpath)
    {
        xmlDoc = new XmlDocument();
        xmlDoc.Load(xmlpath); //加载xml文件

        /*从指定的字符创加载xml文件 例如:
        xmlDoc.LoadXml("(<Book bookID='B001'><BookName>jeff</BookName><price>45.6</price></Book>)");
        */
        XmlNode root = xmlDoc.SelectSingleNode("bookshop");//查找﹤bookstore﹥ 
        XmlElement xe1 = xmlDoc.CreateElement("book");//创建一个﹤book﹥节点 
        xe1.SetAttribute("genre", "Sky_Kwolf");//设置该节点genre属性 
        xe1.SetAttribute("ISBN", "2-3631-4");//设置该节点ISBN属性 

        XmlElement xesub1 = xmlDoc.CreateElement("title");
        xesub1.InnerText = "CSS禅意花圃";//设置节点的文本值 
        xe1.AppendChild(xesub1);//增长到﹤book﹥节点中 
        XmlElement xesub2 = xmlDoc.CreateElement("author");
        xesub2.InnerText = "Jeff";
        xe1.AppendChild(xesub2);
        XmlElement xesub3 = xmlDoc.CreateElement("price");
        xesub3.InnerText = "58.3";
        xe1.AppendChild(xesub3);

        root.AppendChild(xe1);//增长到﹤bookshop﹥节点中 
        xmlDoc.Save(xmlpath); //保留其更改
    }
    ///<summary>
    /// 批改节点
    ///</summary>
    public void UpdateNode(string xmlpath)
    {
        xmlDoc = new XmlDocument();
        xmlDoc.Load(xmlpath); //加载xml文件
        //获取bookshop节点的所有子节点 
        XmlNodeList nodeList = xmlDoc.SelectSingleNode("bookshop").ChildNodes;

        //遍历所有子节点 
        foreach (XmlNode xn in nodeList)
        {
            XmlElement xe = (XmlElement)xn; //将子节点类型转换为XmlElement类型 

            if (xe.GetAttribute("genre") == "Sky_Kwolf")//若是genre属性值为“Sky_Kwolf” 
            {
                xe.SetAttribute("genre", "update Sky_Kwolf"); //则批改该属性为“update Sky_Kwolf” 
                XmlNodeList nls = xe.ChildNodes;//持续获取xe子节点的所有子节点 

                foreach (XmlNode xn1 in nls)//遍历 
                {
                    XmlElement xe2 = (XmlElement)xn1; //转换类型
                    if (xe2.Name == "author")//若是找到 
                    {
                        xe2.InnerText = "jason";//则批改 
                        break;//找到退出 
                    }
                }
                break;
            }
        }

        xmlDoc.Save(xmlpath);//保留。 
    }
    //显示xml数据
    public string ShowXml(string xmlpath)
    {
        string res = "";
        xmlDoc = new XmlDocument();
        xmlDoc.Load(xmlpath); //加载xml文件
        XmlNode xn = xmlDoc.SelectSingleNode("bookshop");

        XmlNodeList xnl = xn.ChildNodes;

        foreach (XmlNode xnf in xnl)
        {
            XmlElement xe = (XmlElement)xnf;
            Console.WriteLine(xe.GetAttribute("genre"));//显示属性值 
            Console.WriteLine(xe.GetAttribute("ISBN"));

            XmlNodeList xnf1 = xe.ChildNodes;
            foreach (XmlNode xn2 in xnf1)
            {
                res += xn2.InnerText;//显示子节点点文本 
            }
        }
        return res;
    }
    ///<summary>
    /// 删除节点
    ///</summary>
    public void DeleteNode(string xmlpath)
    {
        xmlDoc = new XmlDocument();
        xmlDoc.Load(xmlpath); //加载xml文件
        XmlNodeList xnl = xmlDoc.SelectSingleNode("bookshop").ChildNodes;

        foreach (XmlNode xn in xnl)
        {
            XmlElement xe = (XmlElement)xn;

            if (xe.GetAttribute("genre") == "fantasy")
            {
                xe.RemoveAttribute("genre");//删除genre属性 
            }
            else if (xe.GetAttribute("genre") == "update Sky_Kwolf")
            {
                xe.RemoveAll();//删除该节点的全数内容 
            }
        }
        xmlDoc.Save(xmlpath);
    }
    //static void Main(string[] args)
    //{

    //    Program p = new Program();
    //    p.ShowXml();
    //    Console.ReadLine();
    //}

}

#line default
#line hidden