public static T XmlConvertModel<T>(string xmlStr) where T : class, new()
        {
            T t = new T();
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(xmlStr);
            foreach (XmlNode xnls in xmlDoc.ChildNodes)
            {
                if (xnls.Name.ToUpper() == typeof(T).Name.ToUpper())
                {
                    foreach (XmlNode xnl in xnls.ChildNodes)
                    {
                        System.Reflection.PropertyInfo[] propertyInfo = typeof(T).GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
                        foreach (System.Reflection.PropertyInfo pinfo in propertyInfo)
                        {
                            if (xnl.Name.ToUpper() == pinfo.Name.ToUpper())
                            {
                                pinfo.SetValue(t, xnl.InnerText, null);
                                break;
                            }
                        }
                    }
                }
            }
            return t;

}

C# 不是序列化xml 转实体Model【原家独创】的更多相关文章

  1. C#.NET XML 与 实体 MODEL 互转,非序列化

    只能处理简单结构XML 和 实体. using System.Text; using System.Xml; namespace A.Util { public static class MyXmlU ...

  2. c# XML和实体类之间相互转换(序列化和反序列化)[砖]

    link: http://blog.okbase.net/haobao/archive/62.html by: 好饱 我们需要在XML与实体类,DataTable,List之间进行转换,下面是XmlU ...

  3. C# XML和实体类之间相互转换(序列化和反序列化)

    我们需要在XML与实体类,DataTable,List之间进行转换,下面是XmlUtil类,该类来自网络并稍加修改. using System; using System.Collections.Ge ...

  4. XML和实体类之间相互转换(序列化和反序列化)

    我们需要在XML与实体类,DataTable,List之间进行转换,下面是XmlUtil类,该类来自网络并稍加修改. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ...

  5. 用C#实现XML和实体类之间序列化和反序列化相互转换

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.I ...

  6. asp.net webapi 序列化为xml 时实体属性增加<![CDATA[]]>防止特殊字符

    有时webapi在序列化xml时,可能需要给某些带有html或特殊字符(如 < > & /)的字段加上<![CDATA[]]> 已防止影响xml正常数据,如果使用.as ...

  7. 微信支付的JAVA SDK存在漏洞,可导致商家服务器被入侵(绕过支付)XML外部实体注入防护

    XML外部实体注入 例: InputStream is = Test01.class.getClassLoader().getResourceAsStream("evil.xml" ...

  8. WCF中序列化(XML\JSON\Dt)

    序列化 是将对象转换为容易传输的格式的过程.例如,可以序列化一个对象,然后使用 HTTP 通过 Internet 在客户端和服务器之间传输该对象.反之,反序列化根据流重新构造对象. 序列化描述了持久化 ...

  9. XML与 实体的相互转化

    using System; using System.Linq; using System.Xml; using System.Reflection; using System.Data; using ...

随机推荐

  1. SWLU:主核性能采样、调试工具包

    http://bbs.nsccwx.cn/topic/262/swlu-主核性能采样-调试工具包

  2. 用google translate大文件

    问题: google translate对于大文件不支持,咋办? 思路:自己写个函数把的文件拆成小文件,再用google translate! code: from googletrans impor ...

  3. script 命令/方法/函数

    $redis->script('load', $script); $redis->script('flush'); $redis->script('kill'); $redis-&g ...

  4. postgre级联更新

    常规写法 update t_table_copy a set content=( select content from t_table b where a.id = b.id ); 这些法,数据少了 ...

  5. 【转】暴力破解无线WiFi密码

    # coding:utf-8 import pywifi from pywifi import const import time from asyncio.tasks import sleep cl ...

  6. Spring cloud微服务安全实战-4-6搭建OAuth2资源服务器

    认证服务器已经搭建好了. 可以通过认证服务器拿到令牌 下面改造订单服务,让它可以用这个令牌. 争对订单服务要做三个事, 1.让订单服务知道它自己是Oauth协议里面的资源服务器.,它知道这个事后,它才 ...

  7. js Date.parse()时区问题

    比较两个时间,parse() 方法可解析一个日期时间字符串,并返回 1970/1/1 午夜距离该日期时间的毫秒数.Date.parse时间多了8小时. 正确的方法: var nowDate = Dat ...

  8. 改进初学者的PID-采样时间

    最近看到了Brett Beauregard发表的有关PID的系列文章,感觉对于理解PID算法很有帮助,于是将系列文章翻译过来!在自我提高的过程中,也希望对同道中人有所帮助.作者Brett Beaure ...

  9. 【Leetcode_easy】1037. Valid Boomerang

    problem 1037. Valid Boomerang 参考 1. Leetcode_easy_1037. Valid Boomerang; 完

  10. 【ARTS】01_45_左耳听风-201900916~201900922

    ARTS: Algrothm: leetcode算法题目 Review: 阅读并且点评一篇英文技术文章 Tip/Techni: 学习一个技术技巧 Share: 分享一篇有观点和思考的技术文章 Algo ...