title: Namespace prefix and cdata tags in xml generation for rss feed in Ruby on Rails
body: <p>I need to generate an xml for a feed which looks roughly like this :-</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="iso-8859-1" ?&gt;
  &lt;rss version="2.0" xmlns:g="http://base.google.com/ns/1.0" xmlns:atom="http://www.w3.org/2005/Atom"&gt;
  &lt;channel&gt;
      &lt;item&gt;
          &lt;g:id&gt;&lt;![CDATA[id]]&gt;&lt;/g:id&gt;
          &lt;title&gt;&lt;![CDATA[Product Name]]&gt;&lt;/title&gt;
          &lt;description&gt;&lt;![CDATA[This should be a relatively detailed description with as little formatting as possible.]]&gt;&lt;/description&gt;
          &lt;g:brand&gt;Brand X&lt;/g:brand&gt;
          &lt;g:sale_id&gt;new&lt;/g:sale_id&gt;
      &lt;/item&gt;
      &lt;item&gt;
          Next product...
      &lt;/item&gt;
  &lt;/channel&gt;
  &lt;/rss&gt;
  </code></pre>
  
  <p>My code currently looks something like this :-</p>
  
  <pre><code>xml=Builder::XmlMarkup.new(:indent =&gt; 3)
  xml.instruct!
  xml.rss("version" =&gt; "2.0" ,  "xmlns:g" =&gt; "http://base.google.com/ns/1.0" , "xmlns:atom" =&gt; "http://www.w3.org/2005/Atom"){
  xml.channel{
  # remove xml.namespace = xml.namespace_definitions.find{|ns|ns.prefix=="atom"}
  sale_products.each do |sp|
    sid = (products_info[sp.product_id]["sale_id"]).to_s()
    xml.item {
      #xml.id{ |xml| xml.cdata!(products_info[sp.product_id].own_id) }
      #xml.g :id,{ xml.cdata!("sdaf") }
      xml.product_title{ |xml| xml.cdata!(products_info[sp.product_id].name) }
      xml.description{ |xml| xml.cdata!(ActionController::Base.helpers.strip_tags(products_info[sp.product_id].description)) }
      xml.item {
        xml.brand { |xml| xml.cdata!(products_info[sp.product_id].designer_1) }
        xml.sale_id{ |xml| xml.cdata!(sid) }
      }
    }
  
  end
  }
  }
  </code></pre>
  
  <p>My problem is around getting both namespace prefixes and cdata tags working at the same time.</p>
  
  <pre><code>xml.g :id, "fdsafsad"
  </code></pre>
  
  <p>This gets the namesapce prefix.</p>
  
  <pre><code>xml.product_title{ |xml| xml.cdata!(products_info[sp.product_id].name) }
  </code></pre>
  
  <p>This gets cdata tags around the values.</p>
  
  <pre><code>xml.g :id,{ xml.cdata!("sdaf") }
  </code></pre>
  
  <p>This fails to do the trick.</p>
  
  <p>How do i get both the namespace prefix as well as the cdata tags working at the same time for the same tag. What am I doing wrong?</p>
  
  <p><strong>Edit</strong>:- The output that I am currently getting is like:- </p>
  
  <pre><code>&lt;g:id&gt;
     &lt;![CDATA[10005-0003]]&gt;
  &lt;/g:id&gt;
  </code></pre>
  
  <p>The output that I want should just have the value inside cdata tags (no newline etc) :-</p>
  
  <pre><code>&lt;g:id&gt;&lt;![CDATA[10005-0003]]&gt;&lt;/g:id&gt;
  </code></pre>
  
  <p>Note that I do not want to remove the :indent => 3 while creating the markup, so that other tags are formatted as required.</p>