91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

生成和讀取XML文件的方法

發布時間:2020-06-12 06:13:23 來源:網絡 閱讀:367 作者:蒼穹斷雪 欄目:編程語言

自己根據網上現有的代碼,改寫而成的。

生成XML文件的代碼:

/// <summary>
        ///
        /// </summary>
        /// <param name="dt">需要傳的參數</param>
        public static void getXml(DataTable dt)
        {
            string path = System.Web.HttpContext.Current.Server.MapPath("~/XML//");//生成文件所在的位置
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            path += "Plant.xml";//文件名稱
            exportToXml(path, dt);
        }
        /// <summary>
        /// 生成XML文件
        /// </summary>
        /// <param name="filename">文件路徑</param>
        /// <param name="dt">數據源</param>
        public static void exportToXml(string filename, DataTable dt)
        {
            StreamWriter sr = new StreamWriter(filename, false, System.Text.Encoding.UTF8);
            //寫文件頭部內容
            //下面是生成RSS的OPML文件
            sr.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
            sr.WriteLine("<Vote>");
            sr.WriteLine("<VoteInfo><ID>1</ID><VoteTitle></VoteTitle>");
            int i = 0;
           
            if (dt.Rows.Count > 0)
            {
                for (int k = 0; k < dt.Rows.Count;k++ )
                {
                    i++;
                    if (k == 0)
                    {
                        sr.WriteLine("<Item>");
                        sr.WriteLine("<VoteID>" + i + "</VoteID>");
                        sr.WriteLine("<Title>" + Convert.ToDateTime(dt.Rows[k]["Addtime"].ToString()).ToLongDateString() + "</Title>");
                        string shen = "";
                        string unit = "";
                        string m = dt.Rows[k]["Height"].ToString();
                        Regex reg = new Regex(@"[^0-9,^.]+");
                        Regex reg2 = new Regex(@"[^A-Za-z]+");
                        shen = reg.Replace(m, "");
                        unit = reg2.Replace(m, "");
                        sr.WriteLine("<Unit>"+unit+"</Unit>");
                        sr.WriteLine("<Count>" + shen + "</Count>");
                        sr.WriteLine("</Item>");
                    }
                    else
                    {
                        sr.WriteLine("<Item>");
                        sr.WriteLine("<VoteID>" + i + "</VoteID>");
                        sr.WriteLine("<Title>" + Convert.ToDateTime(dt.Rows[k-1]["Updatetime"].ToString()).ToLongDateString() + "</Title>");

                        string shen = "";
                        string unit = "";
                        string m = dt.Rows[k]["Height"].ToString();
                        Regex reg = new Regex(@"[^0-9,^.]+");
                        Regex reg2 = new Regex(@"[^A-Za-z]+");
                        shen = reg.Replace(m, "");
                        unit = reg2.Replace(m, "");
                        sr.WriteLine("<Unit>" + unit + "</Unit>");
                        sr.WriteLine("<Count>" + shen + "</Count>");
                        sr.WriteLine("</Item>");
                    }
                }
            }

            //寫文件尾部內容
            sr.WriteLine("</VoteInfo>");
            sr.WriteLine("</Vote>");
            sr.Close();
        }

讀取xml文件的代碼:

/// <summary>
        /// 獲取xml中的數據()
        /// </summary>
        /// <param name="xdata">x軸數據</param>
        /// <param name="ydata">y軸數據</param>
        /// <param name="unit">單位</param>
        public static void getXML(string xdata, string ydata, string unit)
        {
            XmlDocument myDoc = new XmlDocument();
            myDoc.Load(System.Web.HttpContext.Current.Server.MapPath("~/XML//Plant.xml"));

            XmlNode xn = myDoc.SelectSingleNode("//VoteInfo[ID='1']");//讀取數據源

            XmlNodeList xnl = xn.SelectNodes("Item");

            for (int i = 0; i < xnl.Count; i++)
            {
                XmlNode xn0 = xnl.Item(i);
                ydata += xn0.SelectSingleNode("Count").InnerText + ",";
                xdata += "\'" + xn0.SelectSingleNode("Title").InnerText + "\'" + ",";
                unit = xn0.SelectSingleNode("Unit").InnerText;
            }
            ydata = ydata.Remove(ydata.Length - 1, 1);
            xdata = xdata.Remove(xdata.Length - 1, 1);
        }

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

长沙县| 建瓯市| 大冶市| 连山| 宁河县| 台山市| 祁连县| 平乡县| 库尔勒市| 友谊县| 靖边县| 贵德县| 秦安县| 赞皇县| 邻水| 卢龙县| 临泽县| 宁安市| 定安县| 横峰县| 惠水县| 新营市| 察哈| 翁牛特旗| 烟台市| 聊城市| 临澧县| 色达县| 大冶市| 福安市| 乌审旗| 应用必备| 神池县| 玉门市| 浦北县| 栖霞市| 大田县| 涿鹿县| 资中县| 淮北市| 台东县|