Namespace prefix and cdata tags in xml generation for rss feed in Ruby on Rails

ridata

New Member
I need to generate an xml for a feed which looks roughly like this :-\[code\] <?xml version="1.0" encoding="iso-8859-1" ?><rss version="2.0" xmlns:g="http://base.google.com/ns/1.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel> <item> <g:id><![CDATA[id]]></g:id> <title><![CDATA[Product Name]]></title> <description><![CDATA[This should be a relatively detailed description with as little formatting as possible.]]></description> <g:brand>Brand X</g:brand> <g:sale_id>new</g:sale_id> </item> <item> Next product... </item></channel></rss>\[/code\]My code currently looks something like this :-\[code\]xml=Builder::XmlMarkup.new(:indent => 3)xml.instruct!xml.rss("version" => "2.0" , "xmlns:g" => "http://base.google.com/ns/1.0" , "xmlns:atom" => "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\]My problem is around getting both namespace prefixes and cdata tags working at the same time.\[code\]xml.g :id, "fdsafsad"\[/code\]This gets the namesapce prefix.\[code\]xml.product_title{ |xml| xml.cdata!(products_info[sp.product_id].name) }\[/code\]This gets cdata tags around the values.\[code\]xml.g :id,{ xml.cdata!("sdaf") }\[/code\]This fails to do the trick.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?
 
Back
Top