对象生成 XML

对象模型


    public class ReeferSettings
    {
        [XmlAttribute("AtmosphereType")]
        public string AtmosphereType { get; set; }

        [XmlAttribute("PreCooling")]
        public string PreCooling { get; set; }


        [XmlElement("DehumidityPercentage")]
        public string DehumidityPercentage { get; set; }


        [XmlElement("Remarks")]
        public Remark Remark { get; set; }

    }

XmlAttribute  元素节点属性

XmlElement 元素节点


        public static string XmlSerialize<T>(T obj, out string msg)
        {
            msg = string.Empty;
            try
            {
                using (StringWriter sw = new StringWriter())
                {
                    Type t = obj.GetType();
                    XmlSerializer serializer = new XmlSerializer(t);
                    serializer.Serialize(sw, obj);
                    return sw.ToString();
                }
            }
            catch (Exception ex)
            {
                msg = "生成XML失败 :" + ex.Message;
                return "生成XML失败";
            }
        }

timezone:XmlAttribute 

“HKT”:XmlAttribute  的value

data:XmlElement

20180711172648:XmlElement 的value

猜你喜欢

转载自blog.csdn.net/lygachao/article/details/83185538
今日推荐