I am currently trying to deserialize some XML in the following format:
<content:encoded>![CDATA[...
And I have an object which has a property which looks like:
[XmlElementAttribute("content")]
public string Content { get; set; }
However despite the XML always having a value the property in the code is always null?
contentis a namespace in your example. Your element name is actuallyencodedso you will need to use the attribute marking your property as such:Note that you will need to declare the namespace in your containing XML:
This also means any child nodes would be prefixed with the same namespace. Not so much an issue for
CDATAcontent, but just in case you have other elements you are trying to deserialize.For a related questions to this, see Deserializing child nodes outside of parent's namespace using XmlSerializer.Deserialize() in C#