我需要对以下xml文件进行反序列化/序列化处理:
<items att1="val">
<item att1="image1.jpg">
<![CDATA[<strong>Image 1</strong>]]>
</item>
<item att1="image2.jpg">
<![CDATA[<strong>Image 2</strong>]]>
</item>
</items>
我的C#类:
[Serializable]
[XmlRoot("items")]
public class RootClass
{
[XmlAttribute("att1")]
public string Att1 {set; get;}
[XmlElement("item")]
public Item[] ArrayOfItem {get; set;}
}
[Serializable]
public class Item
{
[XmlAttribute("att1")]
public string Att1 { get; set; }
[XmlText]
public string Content { get; set; }
}
一切都几乎完美地运行,但是在反序列化之后出现了问题
<![CDATA[<strong>Image 1</strong>]]>
我会
<strong>Image 1</strong>
我试图将XmlCDataSection作为Content属性的类型,但是这种类型与XmlText属性不允许一起使用。不幸的是,我无法更改XML结构。
我该如何解决这个问题?
<![CDATA[<strong>Image 1</strong>]]>
和<strong>Image 1</strong>
是同一件事情。你的问题在哪里? - Tomalak