从xml文件中读取一个接点或者多个

来源:互联网 发布:加工中心键槽怎么编程 编辑:程序博客网 时间:2024/05/01 11:20

        /// <summary>
        /// Get jig name by ElementName
        /// </summary>
        /// <param name="strElementName"></param>
        /// <returns></returns>
        public string GetOneContent(string strElementName)
        {
            string strCont = null;
            try
            {
                m_xmlReader = new XmlTextReader(m_strConfigFileName);
                while (m_xmlReader.Read())
                {
                    if (m_xmlReader.LocalName.Equals(strElementName))
                    {
                        strCont = m_xmlReader.ReadString();
                    }
                }
                m_xmlReader.Close();
                if (string.IsNullOrEmpty(strCont))
                {
                    MSException me = new MSException("MIMT1001");
                    throw me;

                }
                else
                {
                    return strCont;
                }
            }
            catch (Exception se)
            {

                if (se is MSException)
                {

                    throw se;

                }

                else
                {

                    MSException me = new MSException("MIMT10011");

                    MSLogger.LogError("MSXmlHandler/GetOneContent()", se.Message, me.Message);

                    throw me;

                }

            }

        }

        /// <summary>
        /// return more than one elemnt for jig machine configuration
        /// </summary>
        /// <param name="strElementName"></param>
        /// <returns></returns>
        public ArrayList GetManyContents(string strElementName)
        {
            try
            {
                ArrayList arrLstContent = new ArrayList();
                m_xmlReader = new XmlTextReader(m_strConfigFileName);
                while (m_xmlReader.Read())
                {
                    if (m_xmlReader.LocalName.Equals(strElementName))
                    {
                        arrLstContent.Add(m_xmlReader.ReadString());

                    }
                }
                m_xmlReader.Close();
                return arrLstContent;
            }
            catch (Exception se)
            {

                if (se is MSException)
                {

                    throw se;

                }

                else
                {

                    MSException me = new MSException("MIMT10011");

                    MSLogger.LogError("MSXmlHandler/GetManyContents()", se.Message, me.Message);

                    throw me;

                }

            }
        } 

原创粉丝点击