您的位置:首页 > 其它

读取XML文件

2007-04-30 14:30 162 查看
1、xml文件格式

 
<?xml version="1.0" encoding="utf-8" ?>
<NodeList>
 <Node text="GWGL"></Node>
 <Node text="手册备案" clsid="表头">
    <Name>GWGL.EP_PRE_EMS3_CUS_HEAD</Name>
    <Value>TRADE_CODE</Value>
 </Node>
 <Node text="手册备案" clsid="单损耗">
    <Name>GWGL.EP_PRE_EMS3_CUS_CONSUME</Name>
    <Value>TRADE_CODE</Value>
    <Value>EXG_NO</Value>
    <Value>IMG_NO</Value>
 </Node>
</NodeList>

2、读取XML文件的函数
/// <summary>
        /// 读取XML文件
        /// </summary>
        /// <param name="Name">节点名称</param>
        /// <param name="classid">扩展选项类别</param>
        /// <param name="DataObj">数据源</param>
        public void ReadXML(string Name, string classid, DataRowView DataObj)
        {
            try
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(Application.StartupPath + "//Configure.xml");
                XmlNodeList node = doc.SelectSingleNode("NodeList").ChildNodes;
                XmlNode Targetnode = null;
                string s = node[0].Attributes["text"].Value;
                for (int i = 1; i < node.Count; i++)
                {
                    if (node[i].Attributes["text"].Value == Name
                        && node[i].Attributes["clsid"].Value == classid )
                    {
                        Targetnode = node[i];
                        break;
                    }
                }
                if (Targetnode != null)
                {
                    //this.toolStrip1.Visible = true;
                    Count = Targetnode.ChildNodes.Count;
                    List = new string[Count];
                    for (int j = 0; j < Count; j++)
                    {
                        List[j] = Targetnode.ChildNodes[j].InnerText;
                    }
                    ExtendTable = List[0];
                    //for (int i = 1; i < Count; i++)
                    //{
                    //    ColumnName[i] = List[i];
                    //}
                    GetData(DataObj, s);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息