现在的位置: 首页 > 综合 > 正文

c#调用xml保存的模板

2013年10月19日 ⁄ 综合 ⁄ 共 2075字 ⁄ 字号 评论关闭

        /// <summary>
        /// 返回模板方法
        /// </summary>
        /// <param name="i"></param>
        /// <returns></returns>
        private void getXmlContent(string strValue)
        {
            string strText = "";

            //xml文件路径
            string strFliePath = Server.MapPath("/Temple/TempleXMLFile.xml");
            XmlDocument xmldoc = new XmlDocument();
            xmldoc.Load(strFliePath);

            XmlNodeList rootelement = xmldoc.DocumentElement.ChildNodes;//根节点

            foreach (XmlElement element in rootelement)  //父节点temple
            {
                if (element.Name.ToLower() == "temple")
                {
                    XmlNodeList temple_nodelist = element.ChildNodes;

                    if (temple_nodelist.Count > 0)
                    {
                        foreach (XmlNode node in temple_nodelist)
                        {
                            if (node.Name.ToLower() == "temple_name" ) //取与选项相同的值
                            {
                                if (node.Attributes["Temple_Value"].Value == strValue) //strValue比对参数
                                {
                                    XmlNode content_node = node.NextSibling;

                                    if (content_node.HasChildNodes)
                                    {
                                        XmlNodeList nodeli = content_node.ChildNodes;

                                        foreach (XmlNode mynode in nodeli)
                                        {
                                            strText += mynode.ChildNodes[0].Value + ":/n";
                                        }

                                        TextBox2.Text = strText;
                                    }
                                    else
                                    {
                                        TextBox2.Text = strText;
                                    }
                                }
                                else
                                {
                                    continue;
                                }
                            }

                        }
                    }
                }
            }

        }

抱歉!评论已关闭.