string转xml 忽略根节点

private static T XmlDeSerialize<T>(string xmlStr) where T : class
    {
        try
        {
            using var sr = new StringReader(xmlStr);
            var serializer = new XmlSerializer(typeof(T), new XmlRootAttribute("xml"));
            return (serializer.Deserialize(sr) as T)!;
        }
        catch (Exception)
        {
            return default!;
        }
    }
posted @ 2022-02-14 11:04  kele-cc  阅读(46)  评论(0)    收藏  举报