XmlSerializer 实现序列化CDATA

Posted 沙耶

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了XmlSerializer 实现序列化CDATA相关的知识,希望对你有一定的参考价值。

     [XmlIgnore]
        public string GuestRemarks { get; set; }

        [XmlElement("GuestRemarks")]
        public XmlNode[] Nodes
        {
            get
            {
                var dom = new XmlDocument();
                return new XmlNode[] {dom.CreateCDataSection(this.GuestRemarks)};
            }
            set
            {
                if (value == null)
                {
                    this.GuestRemarks = null;
                    return;
                }

                if (value.Length != 1)
                    throw new InvalidOperationException("Invalid array.");
                var content = value[0];
                if (null == content)
                    throw new InvalidOperationException("Node is null.");
                this.GuestRemarks = content.Value;
            }
        }

 

以上是关于XmlSerializer 实现序列化CDATA的主要内容,如果未能解决你的问题,请参考以下文章