CDATA processing in XML Data Binding

The default behavior for processing CDATA is to remove the CDATA tags, allowing for easier display and usage of the contained values. To retain the tags, set StripCDATA to false in the XmlSerializationContext, though you’ll need to handle tag removal manually for presentation. This applies to both simple and extended string elements.


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

Discover more from Liquid Technologies Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading