Fog Creek Software
Discussion Board

Welcome! and rules

Joel on Software

XmlSerialize and (not) Entity Encoding

I am using XmlSerializer to output as Xml the data in a class. 

My problem is that some of the class member data contains xhtml, and the serializer is escaping the the angle brackets.

Is there some way to have XmlSerializer *not* escape the data?  I'd prefer to not serialize to a string and then decode.

Friday, May 21, 2004

You can't just have the angle brackets there,  the text has to be escaped, how else do you parse the information?

Or do you mean you want to store the XHTML as a namespaced section of the serialization document?  All this shouldn't matter, when your application 'unserializes' the data, it'll be as you left it.  <'s and all.

Saturday, May 22, 2004

<![CDATA[ ... ]]> is the way to store un-encoded data in an XML document. I don't know if is possible to specify CDATA when using XmlSerializer though.

Duncan Smart
Sunday, May 23, 2004

I didn't explain myself very will. 

The resulting xml document will have an element (say "Description") which comes from a class member also named "Description". 

The class member is populated from a database column which may have xhtml (p, ul, li, etc.), i.e. in general is an xml node.  The serializer treats the tags as text content of the parent element rather than child elements, and so escapes them.  I don't want them escaped.

Sunday, May 23, 2004

Well,  they're *not* child elements.  They're from a different schema so the serializer won't do exactly what you're after. 

Another option is, as I mentioned, to store them as a seperate namespace,  but I don't know if the Serializer can be coaxed into doing this.  For an example, see how Don Box stores HTML in his RSS

Sunday, May 23, 2004

Maybe I have misunderstood the problem, but if not I have come up with a solution. The xml text to include in serialization can be wrapped in an XmlDocument.

private string xmlData;
public XmlDocument XmlData
        XmlDocument doc = new XmlDocument();
        return doc;
    set {}

Mårten Gustafsson
Tuesday, June 8, 2004

*  Recent Topics

*  Fog Creek Home