public static T XmlDataToModel<T>(String xmlData)
    {
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.LoadXml(xmlData);

        XmlElement element = xmlDoc.DocumentElement;

        T objModel = System.Activator.CreateInstance<T>();
        foreach (XmlNode childNode in element.ChildNodes)
        {
            PropertyInfo pi = objModel.GetType().GetProperty(childNode.Name);
            if (pi == null) continue;
            if (!String.IsNullOrEmpty(childNode.InnerXml.Trim()))
                pi.SetValue(objModel, childNode.InnerXml, null);
        }

        return objModel;
    }

  调用:XMLHelper.XmlDataToModel<实体对象类>(封装实体信息的string类型XML);

相关文章:

  • 2021-12-29
  • 2021-12-01
  • 2021-10-05
  • 2022-01-10
  • 2022-01-27
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-12
  • 2022-02-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-31
  • 2022-12-23
相关资源
相似解决方案