c# - How can I put unescaped XML into the XmlText field for a class? -


i have class want put xml (html, actually) unescaped. not conform specification since can arbitrary html. how can achieve declaratively?

ex:

public class material {     [xmlelement(elementname = "mattext")]     public string materialtext { get; set; }       public bool shouldserializematerialtext()     {         return !string.isnullorempty(materialtext);     } } 

if put: <p>test</p> materialtext, produces &lt;p&gt;test&lt;/p&gt; in it's serialized output. how can modify produce string literal xml instead of escaped sequence?

to clear, output i'm looking is: <mattext><p>test</p></mattext>

btw - isn't first choice, else's schema must, unfortunately, adhered to.

thanks!

if cannot use cdata section, have use following workaround:

public class material {     [xmlignore]     public string materialtext { get; set; }       [xmlelement(elementname = "mattext")]     public xmlelement mattext     {         {             var doc = new xmldocument();             doc.loadxml(materialtext);             return doc.documentelement;         }         set { /* implement in similar way */ }    } 

(you of course add kind of caching getter)


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -