This is when using XDocument from .net.
I thought this might work...
xElement.Element(elementName).Value = new XCData(value).ToString();
... but it comes out like this...
<name><![CDATA[hello world]]></name>
XCData is a type of XNode. As such, you should try to Add it to the element, rather than set the value (which is documented to be the flattened text content of the element):
xElement.Element(elementName).Add(new XCData(value));
If you are creating the XElement (vs. modifying it), you can also just add add it directly in the constructor as the content like so:
new XElement(elementName, new XCData(value));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With