run in this way,   no why,   only for you heart
CSDN博客(点击进入) CSDN
51CTO(点击进入) 51CTO

string 转化 xml,并找到指定节点及节点值



            //这是一个符合xml格式的字符串
            string xml = "<xmn> <people><name>zs</name><age>22</age></people> <people><name>ls</name><age>23</age></people> </xmn>";

            //将string 转化为 XmlDocument对象的xml格式
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(xml);

            //查找单节点SelectSingleNode,如果存在多个相同节点,默认查找第一个
            XmlNode nameNode = xmlDoc.SelectSingleNode("//name");   
            string name = nameNode.InnerText;   //zs

            //查找所有节点
            XmlNodeList nameNodeList = xmlDoc.SelectNodes("//people");

            //遍历取值
            foreach (XmlNode nameInfo in nameNodeList)
            {
                string nameValue = (nameInfo.SelectSingleNode("name")).InnerText;
            }



posted @ 2018-09-13 17:37  _小龙人  阅读(...)  评论(...编辑  收藏
everyone want to success in this way,   but isn't easy,   i believe i can