讀取xml中的指定節點的值


 /// <summary>  
        /// 讀取xml中的指定節點的值
        /// </summary>  
        private string ReadXmlNode(string filename)
        {
            string result = "-1";
            XmlDocument xmlDoc = new XmlDocument();
            try
            {
                xmlDoc.LoadXml(filename);
                //讀取Activity節點下的數據。SelectSingleNode匹配第一個Activity節點
                XmlNode root = xmlDoc.SelectSingleNode("//head");//當節點Workflow帶有屬性是,使用SelectSingleNode無法讀取        
                if (root != null)
                    result = (root.SelectSingleNode("code")).InnerText;

            }
            catch //(Exception e)
            {
                //顯示錯誤信息
            }
            return result;
        }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM