Friday, September 26, 2014

CDATA processing in XML Data Binding

The default option when processing CDATA is to strip away the text ![CDATA[ ... ]] leaving just the contained value. This enables you to display and use  the values without the need for parsing. You can then manually add the ![CDATA[ ... ]] text back in when you set the text (i.e. if the user has updated the value).

However, if you prefer to keep the CDATA tag in the element text, you can set StripCDATA = false in the XmlSerializationContext. But you would then need to strip the CDATA tag yourself before displaying the text to the end user.

E.g.
In C# you would set the following:
LiquidTechnologies.Runtime.Net40.XmlSerializationContext.Default.StripCDATA = false

In C++ you would set the following:
LtXmlLib12::CXmlSerializationContext::GetDefaultContext().SetStripCDATA(false);

Note: This behaviour is the same for simple elements defined as string in the XSD and for extended string elements which are accessed using the PrimitiveValue member in the generated source code.

See Also
CDATA processing in XML Data Binding