如何使用XmlSerializer將字符串序列化為CDATA?是否可以通過某種屬性將字符串序列化為使用.Net XmlSerializer的CDATA?
3 回答

蠱毒傳說
TA貢獻(xiàn)1895條經(jīng)驗 獲得超3個贊
[XmlRoot("root")]public class Sample1Xml{ internal Sample1Xml() { } [XmlElement("node")] public NodeType Node { get; set; } #region Nested type: NodeType public class NodeType { [XmlAttribute("attr1")] public string Attr1 { get; set; } [XmlAttribute("attr2")] public string Attr2 { get; set; } [XmlIgnore] public string Content { get; set; } [XmlText] public XmlNode[] CDataContent { get { var dummy = new XmlDocument(); return new XmlNode[] {dummy.CreateCDataSection(Content)}; } set { if (value == null) { Content = null; return; } if (value.Length != 1) { throw new InvalidOperationException( String.Format( "Invalid array length {0}", value.Length)); } Content = value[0].Value; } } } #endregion}
- 3 回答
- 0 關(guān)注
- 1387 瀏覽
添加回答
舉報
0/150
提交
取消