读取XML字符串,获得某个节点中的值

/// <summary>
        /// 读取XML字符串,获得某个节点中的值
        /// </summary>
        /// <param name="strName">节点名称</param>
        /// <returns>节点值</returns>
        public static string GetXml(string strName, string reciveStr)
        {
            XmlTextReader reader = new XmlTextReader(reciveStr, XmlNodeType.Document, null);
            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (reader.Name == strName)
                    {
                        reader.Read();
                        if (XmlNodeType.Text == reader.NodeType)
                        {
                            return reader.Value;
                        }
                    }
                }
            }
            return null;
        }            }
            return null;
        }

posted @ 2012-07-20 17:22  途_途  阅读(524)  评论(0编辑  收藏  举报