简体   繁体   English

Serialize包含XDocument的Property

[英]Serialize Property that contains XDocument

I have a class that I am serializing using System.Xaml.XamlObjectReader and the System.Xaml.XamlXmlWriter . 我有一个类,我使用System.Xaml.XamlObjectReaderSystem.Xaml.XamlXmlWriter序列化。 Everything goes good on everything until I get to my property that contains an XDocument . 在我到达包含XDocument属性之前,一切都很顺利。 I get Unable to serialize type 'System.Xml.Linq.XDeclaration'. 我无法序列化类型'System.Xml.Linq.XDeclaration'。

How can I during my while loop to serialize the object nodes to disk get it to write out the xml in this property? 我怎么能在while循环中将对象节点序列化到磁盘上,让它写出这个属性中的xml?

You can convert this to CData and serialize it. 您可以将其转换为CData并将其序列化。 You can refer this example for details How do you serialize a string as CDATA using XmlSerializer? 您可以参考此示例以获取详细信息如何使用XmlSerializer将字符串序列化为CDATA?

Or you can also escape xml tags of ToString() of XDocument. 或者您也可以转义XDocument的ToString()的xml标记。 eg String escape into XML 例如, 字符串转义为XML

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM