码迷,mamicode.com
首页 > Windows程序 > 详细

C#解析XML

时间:2016-09-21 01:31:20      阅读:231      评论:0      收藏:0      [点我收藏+]

标签:

技术分享
<checkResult>
    <item>
        <fmId>XX0001</fmId>
        <fmItemId>20000RT</fmItemId>
        <checkRuleId>4C6A0458-29B4-4CE6-B38C-38CDEE3CD3C2</checkRuleId>
        <isAcct>不影响</isAcct>
        <soluation>不需要方案,因为不涉及</soluation>
        <evaluate>注意,这是一条评论</evaluate>
    </item>
    <item>
        <fmId>XX0002</fmId>
        <fmItemId>20000RT</fmItemId>
        <checkRuleId>A4C12D83-DC18-427D-839F-7DB68EF730BF</checkRuleId>
        <isAcct>影响</isAcct>
        <soluation>方案还在拟定当中,请注意节奏</soluation>
        <evaluate>It is a evaluate</evaluate>
    </item>
</checkResult>
View Code
技术分享
 public class DizCheckResult
    {
        public string fmId { get; set; }
        public string fmItemId { get; set; }
        public string checkRuleId { get; set; }
        public string isAcct { get; set; }
        public string soluation { get; set; }
        public string evaluate { get; set; }
    }
View Code
技术分享
public static List<DizCheckResult> GetCheckResultList()
        {
            List<DizCheckResult> tmpList = new List<DizCheckResult>();
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(@"f:\myproject\x.xml");
            //XmlNodeList nodelist = xmlDoc.GetElementsByTagName("checkResult/item");
            XmlNodeList nodelist = xmlDoc.SelectNodes("checkResult/item");
            foreach(XmlNode node in nodelist)
            {
                DizCheckResult entity = new DizCheckResult();
                entity.fmId = HttpUtility.HtmlEncode(node["fmId"].InnerText);
                entity.fmItemId = HttpUtility.HtmlEncode(node["fmItemId"].InnerText);
                entity.checkRuleId = node["checkRuleId"].InnerText;
                entity.isAcct = node["isAcct"].InnerText;
                entity.soluation = node["soluation"].InnerText;
                entity.evaluate = node["evaluate"].InnerText;
                tmpList.Add(entity);
            }
            return tmpList;
        }
View Code

 

C#解析XML

标签:

原文地址:http://www.cnblogs.com/lijianhua/p/5891171.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!