c#(.Net)解析xml

//方法1
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\"?><HH><CODE>11</CODE><NAME>kkkk</NAME></HH>");
            XmlNode rootNode = xmlDoc.SelectSingleNode("HH");
            foreach (XmlNode xxNode in rootNode.ChildNodes)
            {
                string dsf = xxNode.InnerText;
                string sdf = xxNode.Name;
            }





 //方法2
            DataSet dsData = new DataSet();
            dsData.ReadXml(new XmlTextReader(new StringReader("<?xml version=\"1.0\" encoding=\"utf-8\"?><HH><CODE>11</CODE><NAME>kkkk</NAME></HH>")));
            DataTable dt = dsData.Tables["HH"];


            foreach (DataRow dr in dt.Rows)
            {
                foreach (DataColumn dc in dr.Table.Columns)
                {
                    string n = dc.ColumnName;
                    string value = dr[n].ToString();
                 }
            }


展开阅读全文

没有更多推荐了,返回首页