# How to add CDATA section in XML file?

**URL:** <https://www.ruby-forum.com/t/how-to-add-cdata-section-in-xml-file/141504>\
**Category:** Ruby\
**Created:** [June 26, 2008, 2:42pm UTC](https://www.ruby-forum.com/t/how-to-add-cdata-section-in-xml-file/141504 "2008-06-26T14:42:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rexml\_query](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ecd19e/32.png) [@rexml\_query](https://www.ruby-forum.com/u/rexml_query)\
**Post date:** [June 26, 2008, 2:42pm UTC](https://www.ruby-forum.com/t/how-to-add-cdata-section-in-xml-file/141504/1 "2008-06-26T14:42:20Z")

</div>

Dear all,

I am fairly new to ruby and am trying to create a CDATA section in an  
XML file. Here is an example of what I am trying to produce:

 \<![CDATA[

]]\>

I have been able to add the section using CData.new. But I get an error  
when trying to add the remaining XML. I thought this code might work:

$xmldata = e11 = Element.new(“TestFlowModel”)  
cdata = CData.new($xmldata)

But unfortunately this gives me a “Object#type is deprecated; use  
Object#class” error.

Any ideas on how I can achieve this? Thank you in advance
